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/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) 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) +}