Skip to content

Commit da641f8

Browse files
committed
Fix printed references to module types
1 parent 42698ae commit da641f8

File tree

2 files changed

+19
-5
lines changed

2 files changed

+19
-5
lines changed

library/src/scala/tasty/util/ShowSourceCode.scala

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -750,9 +750,6 @@ class ShowSourceCode[T <: Tasty with Singleton](tasty0: T) extends Show[T](tasty
750750
printTypeAndAnnots(tp)
751751
this += " "
752752
printAnnotation(annot)
753-
case tpe @ Type.TypeRef(name, _) if name.endsWith("$") =>
754-
printType(tpe)
755-
this += ".type"
756753
case Type.SymRef(ClassDef("Null$" | "Nothing$", _, _, _, _), Type.ThisType(Type.SymRef(PackageDef("runtime", _), NoPrefix()))) =>
757754
// scala.runtime.Null$ and scala.runtime.Nothing$ are not modules, those are their actual names
758755
printType(tpe)
@@ -865,7 +862,8 @@ class ShowSourceCode[T <: Tasty with Singleton](tasty0: T) extends Show[T](tasty
865862
case NoPrefix() | Type.ThisType(Types.EmptyPackage()) =>
866863
case prefix@Type() => printType(prefix) += "."
867864
}
868-
this += name.stripSuffix("$")
865+
if (name.endsWith("$")) this += name.stripSuffix("$") += ".type"
866+
else this += name
869867

870868
case tpe @ Type.Refinement(_, _, _) =>
871869
printRefinement(tpe)
@@ -904,7 +902,15 @@ class ShowSourceCode[T <: Tasty with Singleton](tasty0: T) extends Show[T](tasty
904902
case Type.SymRef(cdef @ ClassDef(_, _, _, _, _), _) if !cdef.flags.isObject =>
905903
printFullClassName(tp)
906904
this += ".this"
907-
case _ => printType(tp)
905+
case Type.TypeRef(name, prefix) if name.endsWith("$") =>
906+
prefix match {
907+
case Types.EmptyPrefix() =>
908+
case _ =>
909+
printTypeOrBound(prefix) += "."
910+
}
911+
this += name.stripSuffix("$")
912+
case _ =>
913+
printType(tp)
908914
}
909915

910916
case Type.TypeLambda(paramNames, tparams, body) =>

tests/run/t8100.decompiled

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
/** Decompiled from out/runTestFromTasty/run/t8100/Test.class */
2+
object Test {
3+
import scala.util.{Try}
4+
def main(args: scala.Array[scala.Predef.String]): scala.Unit = {
5+
def stream: collection.immutable.Stream[scala.None.type] = scala.Stream.from(0).take(100000).map[scala.None.type, collection.immutable.Stream[scala.None.type]](((n: scala.Int) => scala.None))(collection.immutable.Stream.canBuildFrom[scala.None.type])
6+
scala.Predef.println(scala.util.Try.apply[scala.Int](stream.flatten[scala.Nothing](((xo: scala.None.type) => scala.Option.option2Iterable[scala.Nothing](xo))).length))
7+
}
8+
}

0 commit comments

Comments
 (0)