From 39260925b12c2a2d6990c1986cb40adb6fdb1437 Mon Sep 17 00:00:00 2001 From: Nicolas Stucki Date: Sun, 10 Jun 2018 15:27:41 +0200 Subject: [PATCH 1/3] Print ".type" for singleton types --- library/src/scala/tasty/util/ShowSourceCode.scala | 1 + tests/pos/simpleSingleton.decompiled | 9 +++++++++ tests/pos/simpleSingleton.scala | 8 ++++++++ 3 files changed, 18 insertions(+) create mode 100644 tests/pos/simpleSingleton.decompiled create mode 100644 tests/pos/simpleSingleton.scala diff --git a/library/src/scala/tasty/util/ShowSourceCode.scala b/library/src/scala/tasty/util/ShowSourceCode.scala index c4b18859deec..5d2ab0fb2227 100644 --- a/library/src/scala/tasty/util/ShowSourceCode.scala +++ b/library/src/scala/tasty/util/ShowSourceCode.scala @@ -621,6 +621,7 @@ class ShowSourceCode[T <: Tasty with Singleton](tasty0: T) extends Show[T](tasty case TypeTree.Singleton(ref) => printTree(ref) + 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..ed682f85366b --- /dev/null +++ b/tests/pos/simpleSingleton.decompiled @@ -0,0 +1,9 @@ +/** 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 + () + } +} +object Foo diff --git a/tests/pos/simpleSingleton.scala b/tests/pos/simpleSingleton.scala new file mode 100644 index 000000000000..9269e68cb06e --- /dev/null +++ b/tests/pos/simpleSingleton.scala @@ -0,0 +1,8 @@ +class Foo { + def foo(x: Int) = { + val a: x.type = x + val b: Foo.type = Foo + } +} + +object Foo From b86b76ffad223ce3483135c041ce71c58e7068dd Mon Sep 17 00:00:00 2001 From: Nicolas Stucki Date: Sun, 10 Jun 2018 15:46:39 +0200 Subject: [PATCH 2/3] Do not print lazy vals from inner objects --- library/src/scala/tasty/util/ShowSourceCode.scala | 3 ++- tests/pos/simpleSingleton.decompiled | 5 ++++- tests/pos/simpleSingleton.scala | 5 ++++- 3 files changed, 10 insertions(+), 3 deletions(-) diff --git a/library/src/scala/tasty/util/ShowSourceCode.scala b/library/src/scala/tasty/util/ShowSourceCode.scala index 5d2ab0fb2227..1c2b55ad8a72 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 diff --git a/tests/pos/simpleSingleton.decompiled b/tests/pos/simpleSingleton.decompiled index ed682f85366b..8f835b7cee4c 100644 --- a/tests/pos/simpleSingleton.decompiled +++ b/tests/pos/simpleSingleton.decompiled @@ -3,7 +3,10 @@ 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 Foo { + object Bar +} diff --git a/tests/pos/simpleSingleton.scala b/tests/pos/simpleSingleton.scala index 9269e68cb06e..a581b654e8ab 100644 --- a/tests/pos/simpleSingleton.scala +++ b/tests/pos/simpleSingleton.scala @@ -2,7 +2,10 @@ 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 Foo { + object Bar +} From 91d33f01ae9c8f79dca2135e9da5571dcc8d535a Mon Sep 17 00:00:00 2001 From: Nicolas Stucki Date: Mon, 11 Jun 2018 13:11:34 +0200 Subject: [PATCH 3/3] Do not print ".type" for singleton literal types --- library/src/scala/tasty/util/ShowSourceCode.scala | 5 ++++- tests/pos/simpleSingleton.decompiled | 2 ++ tests/pos/simpleSingleton.scala | 2 ++ 3 files changed, 8 insertions(+), 1 deletion(-) diff --git a/library/src/scala/tasty/util/ShowSourceCode.scala b/library/src/scala/tasty/util/ShowSourceCode.scala index 1c2b55ad8a72..9fd430e28ee1 100644 --- a/library/src/scala/tasty/util/ShowSourceCode.scala +++ b/library/src/scala/tasty/util/ShowSourceCode.scala @@ -622,7 +622,10 @@ class ShowSourceCode[T <: Tasty with Singleton](tasty0: T) extends Show[T](tasty case TypeTree.Singleton(ref) => printTree(ref) - this += ".type" + 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 index 8f835b7cee4c..1c9ee9a2e22e 100644 --- a/tests/pos/simpleSingleton.decompiled +++ b/tests/pos/simpleSingleton.decompiled @@ -4,6 +4,8 @@ class Foo() { 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" () } } diff --git a/tests/pos/simpleSingleton.scala b/tests/pos/simpleSingleton.scala index a581b654e8ab..c358612ab767 100644 --- a/tests/pos/simpleSingleton.scala +++ b/tests/pos/simpleSingleton.scala @@ -3,6 +3,8 @@ class Foo { 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" } }