Skip to content

Commit f093ba2

Browse files
Merge pull request #4715 from dotty-staging/decompile-fix-module-ref
Fix printed references to module types
2 parents 71f3aca + 7e70271 commit f093ba2

File tree

2 files changed

+21
-5
lines changed

2 files changed

+21
-5
lines changed

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

Lines changed: 13 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -737,14 +737,12 @@ class ShowSourceCode[T <: Tasty with Singleton](tasty0: T) extends Show[T](tasty
737737

738738
def printTypeTree(tree: TypeTree): Buffer = tree match {
739739
case TypeTree.Synthetic() =>
740+
// TODO try to move this logic into `printType`
740741
def printTypeAndAnnots(tpe: Type): Buffer = tpe match {
741742
case Type.AnnotatedType(tp, annot) =>
742743
printTypeAndAnnots(tp)
743744
this += " "
744745
printAnnotation(annot)
745-
case tpe @ Type.TypeRef(name, _) if name.endsWith("$") =>
746-
printType(tpe)
747-
this += ".type"
748746
case Type.SymRef(ClassDef("Null$" | "Nothing$", _, _, _, _), Type.ThisType(Type.SymRef(PackageDef("runtime", _), NoPrefix()))) =>
749747
// scala.runtime.Null$ and scala.runtime.Nothing$ are not modules, those are their actual names
750748
printType(tpe)
@@ -857,7 +855,8 @@ class ShowSourceCode[T <: Tasty with Singleton](tasty0: T) extends Show[T](tasty
857855
case NoPrefix() | Type.ThisType(Types.EmptyPackage()) =>
858856
case prefix@Type() => printType(prefix) += "."
859857
}
860-
this += name.stripSuffix("$")
858+
if (name.endsWith("$")) this += name.stripSuffix("$") += ".type"
859+
else this += name
861860

862861
case tpe @ Type.Refinement(_, _, _) =>
863862
printRefinement(tpe)
@@ -896,7 +895,16 @@ class ShowSourceCode[T <: Tasty with Singleton](tasty0: T) extends Show[T](tasty
896895
case Type.SymRef(cdef @ ClassDef(_, _, _, _, _), _) if !cdef.flags.isObject =>
897896
printFullClassName(tp)
898897
this += ".this"
899-
case _ => printType(tp)
898+
case Type.TypeRef(name, prefix) if name.endsWith("$") =>
899+
prefix match {
900+
case Types.EmptyPrefix() =>
901+
case _ =>
902+
printTypeOrBound(prefix)
903+
this += "."
904+
}
905+
this += name.stripSuffix("$")
906+
case _ =>
907+
printType(tp)
900908
}
901909

902910
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)