Skip to content

Commit 8aef102

Browse files
Fix Type.prettyPrint on newer versions of Scala 3 - they might have more _ signs in inner classes
1 parent e8490bc commit 8aef102

File tree

1 file changed

+7
-5
lines changed
  • chimney-macro-commons/src/main/scala-3/io/scalaland/chimney/internal/compiletime

1 file changed

+7
-5
lines changed

chimney-macro-commons/src/main/scala-3/io/scalaland/chimney/internal/compiletime/TypesPlatform.scala

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -320,11 +320,13 @@ private[compiletime] trait TypesPlatform extends Types { this: DefinitionsPlatfo
320320

321321
// Classes defined inside a "class" or "def" have package.name.ClassName removed from the type,
322322
// so we have to prepend it ourselves to keep behavior consistent with Scala 2.
323-
if symbolFullName != colorlessReprName && symbolFullName.endsWith("__" + colorlessReprName)
324-
then symbolFullName.substring(0, symbolFullName.length - 2 - colorlessReprName.length) + colorfulReprName
325-
else if symbolFullName != colorlessReprName && symbolFullName.endsWith("_" + colorlessReprName)
326-
then symbolFullName.substring(0, symbolFullName.length - 1 - colorlessReprName.length) + colorfulReprName
327-
else colorfulReprName
323+
if symbolFullName != colorlessReprName then {
324+
val pkg_Len = symbolFullName.length - colorlessReprName.length
325+
(0 to pkg_Len).takeWhile(i => symbolFullName.endsWith(("_" * i) + colorlessReprName)).lastOption match {
326+
case Some(_Len) => symbolFullName.substring(0, pkg_Len - _Len) + colorfulReprName
327+
case None => colorfulReprName
328+
}
329+
} else colorfulReprName
328330
}
329331
.getOrElse(repr.toString)
330332
}

0 commit comments

Comments
 (0)