Skip to content

Commit 02967c9

Browse files
author
Tobias Bordenca
committed
Resugar varargs #4526
Remove annotation from function declaration Explicitly type non sequence literal arguments as varargs in function call (_*)
1 parent 39e6a49 commit 02967c9

File tree

1 file changed

+31
-4
lines changed

1 file changed

+31
-4
lines changed

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

Lines changed: 31 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -344,7 +344,13 @@ class ShowSourceCode[T <: Tasty with Singleton](tasty0: T) extends Show[T](tasty
344344
case Term.Typed(term, tpt) =>
345345
tpt.tpe match {
346346
case Types.Repeated(_) =>
347-
printTree(term)
347+
term match {
348+
case Term.Repeated(_) =>
349+
printTree(term)
350+
case _ =>
351+
printTree(term)
352+
this += ": " += highlightTypeDef("_*", color)
353+
}
348354
case _ =>
349355
inParens {
350356
printTree(term)
@@ -790,9 +796,16 @@ class ShowSourceCode[T <: Tasty with Singleton](tasty0: T) extends Show[T](tasty
790796

791797
case TypeTree.Annotated(tpt, annot) =>
792798
val Annotation(ref, args) = annot
793-
printTypeTree(tpt)
794-
this += " "
795-
printAnnotation(annot)
799+
ref.tpe match {
800+
case Types.RepeatedAnnotation() =>
801+
val Types.Sequence(tp) = tpt.tpe
802+
printType(tp)
803+
this += highlightTypeDef("*", color)
804+
case _ =>
805+
printTypeTree(tpt)
806+
this += " "
807+
printAnnotation(annot)
808+
}
796809

797810
case TypeTree.And(left, right) =>
798811
printTypeTree(left)
@@ -1160,6 +1173,20 @@ class ShowSourceCode[T <: Tasty with Singleton](tasty0: T) extends Show[T](tasty
11601173
}
11611174
}
11621175

1176+
object Sequence {
1177+
def unapply(tpe: Type)(implicit ctx: Context): Option[Type] = tpe match {
1178+
case Type.AppliedType(Type.TypeRef("Seq", Type.SymRef(sym, _)), IsType(tp) :: Nil) if sym.fullName == "scala.collection" => Some(tp)
1179+
case _ => None
1180+
}
1181+
}
1182+
1183+
object RepeatedAnnotation {
1184+
def unapply(tpe: Type)(implicit ctx: Context): Boolean = tpe match {
1185+
case Type.TypeRef("Repeated", Type.SymRef(sym, _)) if sym.fullName == "scala.annotation.internal" => true
1186+
case _ => false
1187+
}
1188+
}
1189+
11631190
object Repeated {
11641191
def unapply(tpe: Type)(implicit ctx: Context): Option[Type] = tpe match {
11651192
case Type.AppliedType(Type.TypeRef("<repeated>", ScalaPackage()), IsType(tp) :: Nil) => Some(tp)

0 commit comments

Comments
 (0)