Skip to content

Do not print trailing comma for empty var args #4703

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 6 additions & 1 deletion library/src/scala/tasty/util/ShowSourceCode.scala
Original file line number Diff line number Diff line change
Expand Up @@ -300,8 +300,13 @@ class ShowSourceCode[T <: Tasty with Singleton](tasty0: T) extends Show[T](tasty
case Term.Select(Term.This(_), "<init>", _) => this += "this" // call to constructor inside a constructor
case _ => printTree(fn)
}
val args1 = args match {
case init :+ Term.Typed(Term.Repeated(Nil), _) => init // drop empty var args at the end
case _ => args
}

this += "("
printTrees(args, ", ")
printTrees(args1, ", ")
this += ")"

case Term.TypeApply(fn, args) =>
Expand Down
1 change: 1 addition & 0 deletions tests/pos/simple-repeated-args.decompiled
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
/** Decompiled from out/posTestFromTasty/pos/simple-repeated-args/Foo.class */
class Foo() {
scala.List.apply[scala.Any](1, "2", '3')
scala.Array.apply(1)
}
1 change: 1 addition & 0 deletions tests/pos/simple-repeated-args.scala
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
class Foo {
List(1, "2", '3')
Array(1)
}