From 02967c9a8615fcc9bc6192cc7df7881fe8a9e99f Mon Sep 17 00:00:00 2001 From: Tobias Bordenca Date: Wed, 26 Sep 2018 17:18:45 +0200 Subject: [PATCH 1/2] Resugar varargs #4526 Remove annotation from function declaration Explicitly type non sequence literal arguments as varargs in function call (_*) --- .../src/scala/tasty/util/ShowSourceCode.scala | 35 ++++++++++++++++--- 1 file changed, 31 insertions(+), 4 deletions(-) diff --git a/library/src/scala/tasty/util/ShowSourceCode.scala b/library/src/scala/tasty/util/ShowSourceCode.scala index 764b0be442bf..98b02d1352c6 100644 --- a/library/src/scala/tasty/util/ShowSourceCode.scala +++ b/library/src/scala/tasty/util/ShowSourceCode.scala @@ -344,7 +344,13 @@ class ShowSourceCode[T <: Tasty with Singleton](tasty0: T) extends Show[T](tasty case Term.Typed(term, tpt) => tpt.tpe match { case Types.Repeated(_) => - printTree(term) + term match { + case Term.Repeated(_) => + printTree(term) + case _ => + printTree(term) + this += ": " += highlightTypeDef("_*", color) + } case _ => inParens { printTree(term) @@ -790,9 +796,16 @@ class ShowSourceCode[T <: Tasty with Singleton](tasty0: T) extends Show[T](tasty case TypeTree.Annotated(tpt, annot) => val Annotation(ref, args) = annot - printTypeTree(tpt) - this += " " - printAnnotation(annot) + ref.tpe match { + case Types.RepeatedAnnotation() => + val Types.Sequence(tp) = tpt.tpe + printType(tp) + this += highlightTypeDef("*", color) + case _ => + printTypeTree(tpt) + this += " " + printAnnotation(annot) + } case TypeTree.And(left, right) => printTypeTree(left) @@ -1160,6 +1173,20 @@ class ShowSourceCode[T <: Tasty with Singleton](tasty0: T) extends Show[T](tasty } } + object Sequence { + def unapply(tpe: Type)(implicit ctx: Context): Option[Type] = tpe match { + case Type.AppliedType(Type.TypeRef("Seq", Type.SymRef(sym, _)), IsType(tp) :: Nil) if sym.fullName == "scala.collection" => Some(tp) + case _ => None + } + } + + object RepeatedAnnotation { + def unapply(tpe: Type)(implicit ctx: Context): Boolean = tpe match { + case Type.TypeRef("Repeated", Type.SymRef(sym, _)) if sym.fullName == "scala.annotation.internal" => true + case _ => false + } + } + object Repeated { def unapply(tpe: Type)(implicit ctx: Context): Option[Type] = tpe match { case Type.AppliedType(Type.TypeRef("", ScalaPackage()), IsType(tp) :: Nil) => Some(tp) From e94f0ef22e79379f71c64317e6c45351b2f96809 Mon Sep 17 00:00:00 2001 From: Tobias Bordenca Date: Wed, 17 Oct 2018 12:18:40 +0200 Subject: [PATCH 2/2] Add tests for varargs and put in whitelist --- compiler/test/dotc/pos-recompilation.whitelist | 2 ++ tests/pos/varargs-position.decompiled | 12 ++++++++++++ tests/pos/varargs-position.scala | 12 ++++++++++++ 3 files changed, 26 insertions(+) create mode 100644 tests/pos/varargs-position.decompiled create mode 100644 tests/pos/varargs-position.scala diff --git a/compiler/test/dotc/pos-recompilation.whitelist b/compiler/test/dotc/pos-recompilation.whitelist index 493e103a524c..7100e52e5a05 100644 --- a/compiler/test/dotc/pos-recompilation.whitelist +++ b/compiler/test/dotc/pos-recompilation.whitelist @@ -38,3 +38,5 @@ t116 t3869 t6225b t704 +varargs +varargs-position diff --git a/tests/pos/varargs-position.decompiled b/tests/pos/varargs-position.decompiled new file mode 100644 index 000000000000..d4459aa8d560 --- /dev/null +++ b/tests/pos/varargs-position.decompiled @@ -0,0 +1,12 @@ +object varargspos { + def g(a: scala.Int, x: scala.Int*): scala.Int = a.+(x.length) + varargspos.g(1, 2, 3, 4) + val xs: collection.immutable.List[scala.Int] = scala.Nil.::[scala.Int](2).::[scala.Int](1) + val a: scala.Int = 8 + val b: scala.Int = 7 + varargspos.g(5, varargspos.xs: _*) + varargspos.g(3, scala.Nil: _*) + varargspos.g(varargspos.a, varargspos.xs: _*) + varargspos.g(varargspos.a, varargspos.b, 2, 3) + varargspos.g(1) +} \ No newline at end of file diff --git a/tests/pos/varargs-position.scala b/tests/pos/varargs-position.scala new file mode 100644 index 000000000000..e0b1abc43e55 --- /dev/null +++ b/tests/pos/varargs-position.scala @@ -0,0 +1,12 @@ +object varargspos { + def g(a: Int, x: Int*) = a + x.length + g(1, 2, 3, 4) + val xs = 1 :: 2 :: Nil + val a = 8 + val b = 7 + g(5, xs: _*) + g(3, Nil: _*) + g(a, xs: _*) + g(a, b, 2, 3) + g(1) +}