Skip to content

Commit 61355f0

Browse files
authored
Merge pull request #4642 from dotty-staging/fix-tasty-relect-singletons
Fix tasty reflect singletons
2 parents 979d2c7 + 91d33f0 commit 61355f0

File tree

3 files changed

+33
-1
lines changed

3 files changed

+33
-1
lines changed

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

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -128,7 +128,8 @@ class ShowSourceCode[T <: Tasty with Singleton](tasty0: T) extends Show[T](tasty
128128
case _ => false
129129
})
130130
}
131-
!flags.isParam && !flags.isParamAccessor && !isCaseClassUnOverridableMethod
131+
def isInnerModuleObject = d.flags.isLazy && d.flags.isObject
132+
!flags.isParam && !flags.isParamAccessor && !isCaseClassUnOverridableMethod && !isInnerModuleObject
132133
}
133134
val stats1 = stats.collect {
134135
case stat@Definition() if keepDefinition(stat) => stat
@@ -623,6 +624,10 @@ class ShowSourceCode[T <: Tasty with Singleton](tasty0: T) extends Show[T](tasty
623624

624625
case TypeTree.Singleton(ref) =>
625626
printTree(ref)
627+
ref match {
628+
case Term.Literal(_) => this
629+
case _ => this += ".type"
630+
}
626631

627632
case TypeTree.Refined(tpt, refinements) =>
628633
printTypeTree(tpt)

tests/pos/simpleSingleton.decompiled

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
/** Decompiled from out/posTestFromTasty/pos/simpleSingleton/Foo.class */
2+
class Foo() {
3+
def foo(x: scala.Int): scala.Unit = {
4+
val a: x.type = x
5+
val b: Foo.type = Foo
6+
val c: Foo.Bar.type = Foo.Bar
7+
val d: 1 = 1
8+
val e: "abc" = "abc"
9+
()
10+
}
11+
}
12+
object Foo {
13+
object Bar
14+
}

tests/pos/simpleSingleton.scala

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
class Foo {
2+
def foo(x: Int) = {
3+
val a: x.type = x
4+
val b: Foo.type = Foo
5+
val c: Foo.Bar.type = Foo.Bar
6+
val d: 1 = 1
7+
val e: "abc" = "abc"
8+
}
9+
}
10+
11+
object Foo {
12+
object Bar
13+
}

0 commit comments

Comments
 (0)