Skip to content

Fix printed references to module types #4715

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Jun 29, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 13 additions & 5 deletions library/src/scala/tasty/util/ShowSourceCode.scala
Original file line number Diff line number Diff line change
Expand Up @@ -745,14 +745,12 @@ class ShowSourceCode[T <: Tasty with Singleton](tasty0: T) extends Show[T](tasty

def printTypeTree(tree: TypeTree): Buffer = tree match {
case TypeTree.Synthetic() =>
// TODO try to move this logic into `printType`
def printTypeAndAnnots(tpe: Type): Buffer = tpe match {
case Type.AnnotatedType(tp, annot) =>
printTypeAndAnnots(tp)
this += " "
printAnnotation(annot)
case tpe @ Type.TypeRef(name, _) if name.endsWith("$") =>
printType(tpe)
this += ".type"
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why the two cases below are not handled in TYPE printing as well ? Can we move the whole method printTypeAndAnnots to TYPE printing part, instead of being a local method inside TREE printing?

case Type.SymRef(ClassDef("Null$" | "Nothing$", _, _, _, _), Type.ThisType(Type.SymRef(PackageDef("runtime", _), NoPrefix()))) =>
// scala.runtime.Null$ and scala.runtime.Nothing$ are not modules, those are their actual names
printType(tpe)
Expand Down Expand Up @@ -865,7 +863,8 @@ class ShowSourceCode[T <: Tasty with Singleton](tasty0: T) extends Show[T](tasty
case NoPrefix() | Type.ThisType(Types.EmptyPackage()) =>
case prefix@Type() => printType(prefix) += "."
}
this += name.stripSuffix("$")
if (name.endsWith("$")) this += name.stripSuffix("$") += ".type"
else this += name

case tpe @ Type.Refinement(_, _, _) =>
printRefinement(tpe)
Expand Down Expand Up @@ -904,7 +903,16 @@ class ShowSourceCode[T <: Tasty with Singleton](tasty0: T) extends Show[T](tasty
case Type.SymRef(cdef @ ClassDef(_, _, _, _, _), _) if !cdef.flags.isObject =>
printFullClassName(tp)
this += ".this"
case _ => printType(tp)
case Type.TypeRef(name, prefix) if name.endsWith("$") =>
prefix match {
case Types.EmptyPrefix() =>
case _ =>
printTypeOrBound(prefix)
this += "."
}
this += name.stripSuffix("$")
case _ =>
printType(tp)
}

case Type.TypeLambda(paramNames, tparams, body) =>
Expand Down
8 changes: 8 additions & 0 deletions tests/run/t8100.decompiled
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
/** Decompiled from out/runTestFromTasty/run/t8100/Test.class */
object Test {
import scala.util.{Try}
def main(args: scala.Array[scala.Predef.String]): scala.Unit = {
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])
scala.Predef.println(scala.util.Try.apply[scala.Int](stream.flatten[scala.Nothing](((xo: scala.None.type) => scala.Option.option2Iterable[scala.Nothing](xo))).length))
}
}