From 5416002a1db45340c932835ab50b9a34c2b83eed Mon Sep 17 00:00:00 2001 From: Nicolas Stucki Date: Mon, 18 Jun 2018 15:31:17 +0200 Subject: [PATCH 1/7] Add missing implicit keyword --- library/src/scala/tasty/util/ShowSourceCode.scala | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/library/src/scala/tasty/util/ShowSourceCode.scala b/library/src/scala/tasty/util/ShowSourceCode.scala index 44e910c524a0..f74459706068 100644 --- a/library/src/scala/tasty/util/ShowSourceCode.scala +++ b/library/src/scala/tasty/util/ShowSourceCode.scala @@ -68,6 +68,7 @@ class ShowSourceCode[T <: Tasty with Singleton](tasty0: T) extends Show[T](tasty printDefAnnotations(cdef) val flags = cdef.flags + if (flags.isImplicit) this += "implicit " if (flags.isFinal && !flags.isObject) this += "final " if (flags.isCase) this += "case " @@ -157,6 +158,7 @@ class ShowSourceCode[T <: Tasty with Singleton](tasty0: T) extends Show[T](tasty printDefAnnotations(vdef) val flags = vdef.flags + if (flags.isImplicit) this += "implicit " if (flags.isOverride) this += "override " if (flags.isLazy) this += "lazy " @@ -210,7 +212,8 @@ class ShowSourceCode[T <: Tasty with Singleton](tasty0: T) extends Show[T](tasty printDefAnnotations(ddef) val flags = ddef.flags - if (flags.isOverride) sb.append("override ") + if (flags.isImplicit) this += "implicit " + if (flags.isOverride) this += "override " this += "def " += name printTargsDefs(targs) From feeec24fc8d80ede7516316ff10d2849d076f975 Mon Sep 17 00:00:00 2001 From: Nicolas Stucki Date: Mon, 18 Jun 2018 15:32:45 +0200 Subject: [PATCH 2/7] Allow type bounds in TypeTree.Applied for wildcard types --- .../tools/dotc/tastyreflect/TastyImpl.scala | 2 +- library/src/scala/tasty/Tasty.scala | 2 +- .../src/scala/tasty/util/ShowExtractors.scala | 4 ++-- .../src/scala/tasty/util/ShowSourceCode.scala | 16 ++++++++-------- tests/pos/t0905.decompiled | 7 +++++++ 5 files changed, 19 insertions(+), 12 deletions(-) create mode 100644 tests/pos/t0905.decompiled diff --git a/compiler/src/dotty/tools/dotc/tastyreflect/TastyImpl.scala b/compiler/src/dotty/tools/dotc/tastyreflect/TastyImpl.scala index e8e5bd926ca3..b9efdf59146d 100644 --- a/compiler/src/dotty/tools/dotc/tastyreflect/TastyImpl.scala +++ b/compiler/src/dotty/tools/dotc/tastyreflect/TastyImpl.scala @@ -572,7 +572,7 @@ object TastyImpl extends scala.tasty.Tasty { } object Applied extends AppliedExtractor { - def unapply(x: TypeTree)(implicit ctx: Context): Option[(TypeTree, List[TypeTree])] = x match { + def unapply(x: TypeTree)(implicit ctx: Context): Option[(TypeTree, List[TypeOrBoundsTree])] = x match { case x: tpd.AppliedTypeTree @unchecked => Some(x.tpt, x.args) case _ => None } diff --git a/library/src/scala/tasty/Tasty.scala b/library/src/scala/tasty/Tasty.scala index d5c67a1ff65f..237d962be2a8 100644 --- a/library/src/scala/tasty/Tasty.scala +++ b/library/src/scala/tasty/Tasty.scala @@ -417,7 +417,7 @@ abstract class Tasty { tasty => val Applied: AppliedExtractor abstract class AppliedExtractor { - def unapply(x: TypeTree)(implicit ctx: Context): Option[(TypeTree, List[TypeTree])] + def unapply(x: TypeTree)(implicit ctx: Context): Option[(TypeTree, List[TypeOrBoundsTree])] } val Annotated: AnnotatedExtractor diff --git a/library/src/scala/tasty/util/ShowExtractors.scala b/library/src/scala/tasty/util/ShowExtractors.scala index 030c6ccc33fd..6f2b0e83c313 100644 --- a/library/src/scala/tasty/util/ShowExtractors.scala +++ b/library/src/scala/tasty/util/ShowExtractors.scala @@ -253,8 +253,8 @@ class ShowExtractors[T <: Tasty with Singleton](tasty0: T) extends Show[T](tasty private implicit class TypeTreeOps(buff: Buffer) { def +=(x: TypeOrBoundsTree): Buffer = { visitTypeTree(x); buff } - def +=(x: Option[TypeTree]): Buffer = { visitOption(x, visitTypeTree); buff } - def ++=(x: List[TypeTree]): Buffer = { visitList(x, visitTypeTree); buff } + def +=(x: Option[TypeOrBoundsTree]): Buffer = { visitOption(x, visitTypeTree); buff } + def ++=(x: List[TypeOrBoundsTree]): Buffer = { visitList(x, visitTypeTree); buff } } private implicit class TypeOps(buff: Buffer) { diff --git a/library/src/scala/tasty/util/ShowSourceCode.scala b/library/src/scala/tasty/util/ShowSourceCode.scala index f74459706068..fdaff6d3d32a 100644 --- a/library/src/scala/tasty/util/ShowSourceCode.scala +++ b/library/src/scala/tasty/util/ShowSourceCode.scala @@ -94,7 +94,7 @@ class ShowSourceCode[T <: Tasty with Singleton](tasty0: T) extends Show[T](tasty this += " " printTypeTree(tpt) this += "[" - printTypeTrees(targs, ", ") + printTypeOrBoundsTrees(targs, ", ") this += "]" if (args.nonEmpty) { this += "(" @@ -274,7 +274,7 @@ class ShowSourceCode[T <: Tasty with Singleton](tasty0: T) extends Show[T](tasty case Term.TypeApply(fn, args) => printTree(fn) this += "[" - printTypeTrees(args, ", ") + printTypeOrBoundsTrees(args, ", ") this += "]" case Term.Super(qual, tptOpt) => @@ -454,12 +454,12 @@ class ShowSourceCode[T <: Tasty with Singleton](tasty0: T) extends Show[T](tasty this } - def printTypeTrees(typesTrees: List[TypeTree], sep: String): Buffer = { - def printSeparated(list: List[TypeTree]): Unit = list match { + def printTypeOrBoundsTrees(typesTrees: List[TypeOrBoundsTree], sep: String): Buffer = { + def printSeparated(list: List[TypeOrBoundsTree]): Unit = list match { case Nil => - case x :: Nil => printTypeTree(x) + case x :: Nil => printTypeOrBoundsTree(x) case x :: xs => - printTypeTree(x) + printTypeOrBoundsTree(x) this += sep printSeparated(xs) } @@ -667,7 +667,7 @@ class ShowSourceCode[T <: Tasty with Singleton](tasty0: T) extends Show[T](tasty def printTypeOrBoundsTree(tpt: TypeOrBoundsTree): Buffer = tpt match { case TypeBoundsTree(lo, hi) => - this += " >: " + this += "_ >: " printTypeTree(lo) this += " <: " printTypeTree(hi) @@ -726,7 +726,7 @@ class ShowSourceCode[T <: Tasty with Singleton](tasty0: T) extends Show[T](tasty case TypeTree.Applied(tpt, args) => printTypeTree(tpt) this += "[" - printTypeTrees(args, ", ") + printTypeOrBoundsTrees(args, ", ") this += "]" case TypeTree.Annotated(tpt, annot) => diff --git a/tests/pos/t0905.decompiled b/tests/pos/t0905.decompiled new file mode 100644 index 000000000000..474310483d61 --- /dev/null +++ b/tests/pos/t0905.decompiled @@ -0,0 +1,7 @@ +/** Decompiled from out/posTestFromTasty/pos/t0905/Test.class */ +object Test { + class A[T]() extends java.lang.Object + def f(implicit p: Test.A[_ >: scala.Nothing <: scala.Any]): scala.Null = null + implicit val x: Test.A[_ >: scala.Nothing <: scala.Any] = null + scala.Predef.println(Test.f(Test.x)) +} From b69e7fa2b3d6cb5d2df8b662326d711e8a3049b3 Mon Sep 17 00:00:00 2001 From: Nicolas Stucki Date: Mon, 18 Jun 2018 15:50:41 +0200 Subject: [PATCH 3/7] Print trait keyword --- library/src/scala/tasty/util/ShowSourceCode.scala | 1 + tests/pos/t0905.decompiled | 2 +- 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/library/src/scala/tasty/util/ShowSourceCode.scala b/library/src/scala/tasty/util/ShowSourceCode.scala index fdaff6d3d32a..c20d5acaf688 100644 --- a/library/src/scala/tasty/util/ShowSourceCode.scala +++ b/library/src/scala/tasty/util/ShowSourceCode.scala @@ -73,6 +73,7 @@ class ShowSourceCode[T <: Tasty with Singleton](tasty0: T) extends Show[T](tasty if (flags.isCase) this += "case " if (flags.isObject) this += "object " += name.stripSuffix("$") + else if (flags.isTrait) this += "trait " += name else this += "class " += name if (!flags.isObject) { diff --git a/tests/pos/t0905.decompiled b/tests/pos/t0905.decompiled index 474310483d61..dba33a22a1ba 100644 --- a/tests/pos/t0905.decompiled +++ b/tests/pos/t0905.decompiled @@ -1,6 +1,6 @@ /** Decompiled from out/posTestFromTasty/pos/t0905/Test.class */ object Test { - class A[T]() extends java.lang.Object + trait A[T]() extends java.lang.Object def f(implicit p: Test.A[_ >: scala.Nothing <: scala.Any]): scala.Null = null implicit val x: Test.A[_ >: scala.Nothing <: scala.Any] = null scala.Predef.println(Test.f(Test.x)) From 6a3e98deab62d9fe89f0ba93e1d59f0e87a16c8f Mon Sep 17 00:00:00 2001 From: Nicolas Stucki Date: Mon, 18 Jun 2018 15:53:59 +0200 Subject: [PATCH 4/7] Update doc --- tests/pos/tasty/definitions.scala | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/pos/tasty/definitions.scala b/tests/pos/tasty/definitions.scala index edc266448b22..a90e6912e7c3 100644 --- a/tests/pos/tasty/definitions.scala +++ b/tests/pos/tasty/definitions.scala @@ -95,7 +95,7 @@ object definitions { case Select(prefix: Term, name: String) case Singleton(ref: Term) case Refined(underlying: TypeTree, refinements: List[Definition]) - case Applied(tycon: TypeTree, args: List[TypeTree]) + case Applied(tycon: TypeTree, args: List[TypeTree | TypeBoundsTree]) case Annotated(tpt: TypeTree, annotation: Term) case And(left: TypeTree, right: TypeTree) case Or(left: TypeTree, right: TypeTree) From d069455b7df2f5aa9d61e7500f1988d7a478ad99 Mon Sep 17 00:00:00 2001 From: Nicolas Stucki Date: Mon, 18 Jun 2018 16:48:23 +0200 Subject: [PATCH 5/7] Fix check file --- tests/pos/i2104b.decompiled | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/pos/i2104b.decompiled b/tests/pos/i2104b.decompiled index 37dfebabc7e0..46201c2fd6ff 100644 --- a/tests/pos/i2104b.decompiled +++ b/tests/pos/i2104b.decompiled @@ -1,5 +1,5 @@ /** Decompiled from out/posTestFromTasty/pos/i2104b/Cons.class */ -class Cons[H, T]() extends java.lang.Object +trait Cons[H, T]() extends java.lang.Object object Cons { def apply[H, T](h: H, t: T): Cons[H, T] = scala.Predef.??? def unapply[H, T](t: Cons[H, T]): scala.Option[Pair[H, T]] = scala.Predef.??? From 06cf544052fc4b11968011e6e30c09c112a8995c Mon Sep 17 00:00:00 2001 From: Nicolas Stucki Date: Mon, 18 Jun 2018 17:02:45 +0200 Subject: [PATCH 6/7] Fix printed type bounds in LambdaTypes --- .../src/scala/tasty/util/ShowSourceCode.scala | 37 +++++++++++-------- tests/pos/i1181.decompiled | 4 +- 2 files changed, 24 insertions(+), 17 deletions(-) diff --git a/library/src/scala/tasty/util/ShowSourceCode.scala b/library/src/scala/tasty/util/ShowSourceCode.scala index c20d5acaf688..d28cad8b4f7d 100644 --- a/library/src/scala/tasty/util/ShowSourceCode.scala +++ b/library/src/scala/tasty/util/ShowSourceCode.scala @@ -500,34 +500,41 @@ class ShowSourceCode[T <: Tasty with Singleton](tasty0: T) extends Show[T](tasty def printTargDef(arg: TypeDef, isMember: Boolean = false): Buffer = { val TypeDef(name, rhs) = arg + def printBounds(bounds: TypeBoundsTree): Buffer = { + val TypeBoundsTree(lo, hi) = bounds + lo match { + case TypeTree.Synthetic() => + case _ => + this += " >: " + printTypeTree(lo) + } + hi match { + case TypeTree.Synthetic() => this + case _ => + this += " <: " + printTypeTree(hi) + } + } this += name rhs match { - case TypeBoundsTree(lo, hi) => - lo match { - case TypeTree.Synthetic() => this - case _ => - this += " >: " - printTypeTree(lo) - } - hi match { - case TypeTree.Synthetic() => this - case _ => - this += " <: " - printTypeTree(hi) - } + case rhs @ TypeBoundsTree(lo, hi) => printBounds(rhs) case rhs @ SyntheticBounds() => printTypeOrBound(rhs.tpe) case rhs @ TypeTree.TypeLambdaTree(tparams, body) => + def printParam(t: TypeOrBoundsTree): Unit = t match { + case t @ TypeBoundsTree(_, _) => printBounds(t) + case t @ TypeTree() => printTypeTree(t) + } def printSeparated(list: List[TypeDef]): Unit = list match { case Nil => case x :: Nil => val TypeDef(name, trhs) = x this += name - printTypeOrBoundsTree(trhs) + printParam(trhs) case x :: xs => val TypeDef(name, trhs) = x this += name - printTypeOrBoundsTree(trhs) + printParam(trhs) this += ", " printSeparated(xs) } diff --git a/tests/pos/i1181.decompiled b/tests/pos/i1181.decompiled index a88d47e927ff..fb585ba66b9d 100644 --- a/tests/pos/i1181.decompiled +++ b/tests/pos/i1181.decompiled @@ -1,7 +1,7 @@ /** Decompiled from out/posTestFromTasty/pos/i1181/Test.class */ object Test { - def foo[M[_$1 >: scala.Nothing <: scala.Any]](x: M[scala.Int]): M[scala.Int] = x - type Alias[A >: scala.Nothing <: scala.Any] = scala.Tuple2[A, A] + def foo[M[_$1]](x: M[scala.Int]): M[scala.Int] = x + type Alias[A] = scala.Tuple2[A, A] val x: Test.Alias[scala.Int] = scala.Tuple2.apply[scala.Int, scala.Int](1, 2) Test.foo[Test.Alias](Test.x) Test.foo[[A >: scala.Nothing <: scala.Any] => scala.Tuple2[A, A]](Test.x) From a264e86146fe1dee0f2eee68b74cccd7dea7add2 Mon Sep 17 00:00:00 2001 From: Nicolas Stucki Date: Mon, 18 Jun 2018 17:24:25 +0200 Subject: [PATCH 7/7] Add annot-bootstrap.scala to correct blacklist --- compiler/test/dotty/tools/dotc/FromTastyTests.scala | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/compiler/test/dotty/tools/dotc/FromTastyTests.scala b/compiler/test/dotty/tools/dotc/FromTastyTests.scala index 9d1c5d13a23e..6c992a0be945 100644 --- a/compiler/test/dotty/tools/dotc/FromTastyTests.scala +++ b/compiler/test/dotty/tools/dotc/FromTastyTests.scala @@ -36,9 +36,11 @@ class FromTastyTests extends ParallelTesting { // MatchError in SymDenotation.sourceModule on a ThisType "t3612.scala", + + // Fails on MacOS + "annot-bootstrap.scala", ), recompilationBlacklist = Set( - "annot-bootstrap.scala", ) ).checkCompile() }