diff --git a/library/src/scala/tasty/util/ShowSourceCode.scala b/library/src/scala/tasty/util/ShowSourceCode.scala index c4b18859deec..9fd430e28ee1 100644 --- a/library/src/scala/tasty/util/ShowSourceCode.scala +++ b/library/src/scala/tasty/util/ShowSourceCode.scala @@ -126,7 +126,8 @@ class ShowSourceCode[T <: Tasty with Singleton](tasty0: T) extends Show[T](tasty case _ => false }) } - !flags.isParam && !flags.isParamAccessor && !isCaseClassUnOverridableMethod + def isInnerModuleObject = d.flags.isLazy && d.flags.isObject + !flags.isParam && !flags.isParamAccessor && !isCaseClassUnOverridableMethod && !isInnerModuleObject } val stats1 = stats.collect { case stat@Definition() if keepDefinition(stat) => stat @@ -621,6 +622,10 @@ class ShowSourceCode[T <: Tasty with Singleton](tasty0: T) extends Show[T](tasty case TypeTree.Singleton(ref) => printTree(ref) + ref match { + case Term.Literal(_) => this + case _ => this += ".type" + } case TypeTree.Refined(tpt, refinements) => printTypeTree(tpt) diff --git a/tests/pos/simpleSingleton.decompiled b/tests/pos/simpleSingleton.decompiled new file mode 100644 index 000000000000..1c9ee9a2e22e --- /dev/null +++ b/tests/pos/simpleSingleton.decompiled @@ -0,0 +1,14 @@ +/** Decompiled from out/posTestFromTasty/pos/simpleSingleton/Foo.class */ +class Foo() { + def foo(x: scala.Int): scala.Unit = { + val a: x.type = x + val b: Foo.type = Foo + val c: Foo.Bar.type = Foo.Bar + val d: 1 = 1 + val e: "abc" = "abc" + () + } +} +object Foo { + object Bar +} diff --git a/tests/pos/simpleSingleton.scala b/tests/pos/simpleSingleton.scala new file mode 100644 index 000000000000..c358612ab767 --- /dev/null +++ b/tests/pos/simpleSingleton.scala @@ -0,0 +1,13 @@ +class Foo { + def foo(x: Int) = { + val a: x.type = x + val b: Foo.type = Foo + val c: Foo.Bar.type = Foo.Bar + val d: 1 = 1 + val e: "abc" = "abc" + } +} + +object Foo { + object Bar +}