Skip to content

Fix tasty reflect singletons #4642

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 3 commits into from
Jun 11, 2018
Merged
Show file tree
Hide file tree
Changes from 2 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
4 changes: 3 additions & 1 deletion library/src/scala/tasty/util/ShowSourceCode.scala
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -621,6 +622,7 @@ class ShowSourceCode[T <: Tasty with Singleton](tasty0: T) extends Show[T](tasty

case TypeTree.Singleton(ref) =>
printTree(ref)
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.

How Constant types are handled?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

They are handled by printConstant. I will check that they are printed correctly.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@liufengyun fixed the literal constant singleton types to not print ".type"


case TypeTree.Refined(tpt, refinements) =>
printTypeTree(tpt)
Expand Down
12 changes: 12 additions & 0 deletions tests/pos/simpleSingleton.decompiled
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
/** 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
()
}
}
object Foo {
object Bar
}
11 changes: 11 additions & 0 deletions tests/pos/simpleSingleton.scala
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
class Foo {
def foo(x: Int) = {
val a: x.type = x
val b: Foo.type = Foo
val c: Foo.Bar.type = Foo.Bar
}
}

object Foo {
object Bar
}