From da641f8dd8ebfdb8659695cf8d4814d4970d5026 Mon Sep 17 00:00:00 2001 From: Nicolas Stucki Date: Wed, 20 Jun 2018 13:58:43 +0200 Subject: [PATCH 1/2] Fix printed references to module types --- .../src/scala/tasty/util/ShowSourceCode.scala | 16 +++++++++++----- tests/run/t8100.decompiled | 8 ++++++++ 2 files changed, 19 insertions(+), 5 deletions(-) create mode 100644 tests/run/t8100.decompiled diff --git a/library/src/scala/tasty/util/ShowSourceCode.scala b/library/src/scala/tasty/util/ShowSourceCode.scala index 06d0287a19bd..66701bd51a39 100644 --- a/library/src/scala/tasty/util/ShowSourceCode.scala +++ b/library/src/scala/tasty/util/ShowSourceCode.scala @@ -750,9 +750,6 @@ class ShowSourceCode[T <: Tasty with Singleton](tasty0: T) extends Show[T](tasty printTypeAndAnnots(tp) this += " " printAnnotation(annot) - case tpe @ Type.TypeRef(name, _) if name.endsWith("$") => - printType(tpe) - this += ".type" 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) @@ -865,7 +862,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) @@ -904,7 +902,15 @@ 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 += name.stripSuffix("$") + case _ => + printType(tp) } case Type.TypeLambda(paramNames, tparams, body) => diff --git a/tests/run/t8100.decompiled b/tests/run/t8100.decompiled new file mode 100644 index 000000000000..98a9f15b651b --- /dev/null +++ b/tests/run/t8100.decompiled @@ -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)) + } +} From 7e70271dba6abbacb7a70ee891404a7c0185e1d2 Mon Sep 17 00:00:00 2001 From: Nicolas Stucki Date: Fri, 29 Jun 2018 08:36:00 +0200 Subject: [PATCH 2/2] Reformat code and add comment --- library/src/scala/tasty/util/ShowSourceCode.scala | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/library/src/scala/tasty/util/ShowSourceCode.scala b/library/src/scala/tasty/util/ShowSourceCode.scala index 66701bd51a39..2677999462ec 100644 --- a/library/src/scala/tasty/util/ShowSourceCode.scala +++ b/library/src/scala/tasty/util/ShowSourceCode.scala @@ -745,6 +745,7 @@ 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) @@ -906,7 +907,8 @@ class ShowSourceCode[T <: Tasty with Singleton](tasty0: T) extends Show[T](tasty prefix match { case Types.EmptyPrefix() => case _ => - printTypeOrBound(prefix) += "." + printTypeOrBound(prefix) + this += "." } this += name.stripSuffix("$") case _ =>