Skip to content

Commit 55fc311

Browse files
committed
Fix printing f repeated arguments
1 parent f9da4d6 commit 55fc311

File tree

3 files changed

+31
-5
lines changed

3 files changed

+31
-5
lines changed

library/src/scala/tasty/util/ShowSourceCode.scala

Lines changed: 24 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -206,11 +206,16 @@ class ShowSourceCode[T <: Tasty with Singleton](tasty0: T) extends Show[T](tasty
206206
// TODO use tptOpt?
207207

208208
case Term.Typed(term, tpt) =>
209-
this += "("
210-
printTree(term)
211-
this += ": "
212-
printTypeTree(tpt)
213-
this += ")"
209+
tpt.tpe match {
210+
case Types.Repeated(_) =>
211+
printTree(term)
212+
case _ =>
213+
this += "("
214+
printTree(term)
215+
this += ": "
216+
printTypeTree(tpt)
217+
this += ")"
218+
}
214219

215220
case Term.Assign(lhs, rhs) =>
216221
printTree(lhs)
@@ -717,6 +722,20 @@ class ShowSourceCode[T <: Tasty with Singleton](tasty0: T) extends Show[T](tasty
717722
case Type.TypeRef("Object", Type.SymRef(PackageDef("lang", _), Type.ThisType(Type.SymRef(PackageDef("java", _), NoPrefix())))) => true
718723
case _ => false
719724
}
725+
726+
object Repeated {
727+
def unapply(tpe: Type)(implicit ctx: Context): Option[Type] = tpe match {
728+
case Type.AppliedType(Type.TypeRef("<repeated>", ScalaPackage()), (tp@Type()) :: Nil) => Some(tp)
729+
case _ => None
730+
}
731+
}
732+
}
733+
734+
private object ScalaPackage {
735+
def unapply(tpe: TypeOrBounds)(implicit ctx: Context): Boolean = tpe match {
736+
case Type.SymRef(PackageDef("scala", _), RootPackage()) => true
737+
case _ => false
738+
}
720739
}
721740

722741
private object RootPackage {
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
/** Decompiled from out/posTestFromTasty/pos/simple-repeated-args/Foo.class */
2+
class Foo() {
3+
scala.List.apply[scala.Any](1, "2", '3')
4+
}

tests/pos/simple-repeated-args.scala

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
class Foo {
2+
List(1, "2", '3')
3+
}

0 commit comments

Comments
 (0)