bug icon indicating copy to clipboard operation
bug copied to clipboard

Scala 3 case class with varargs parameter can't be constructed in Scala 2

Open jadenPete opened this issue 3 months ago • 0 comments

It would seem that case classs compiled in Scala 3 with varargs parameters can't be constructed in Scala 2, because the Scala 2 compiler thinks a Seq should be passed to the apply method instead of a dynamic number of arguments. If this is expected behavior, feel free to close this issue.

Reproduction steps

Scala 2 version: 2.13.16 Scala 3 version: 3.6.3

  1. Clone this minimum reproducability case: https://github.com/jadenPete/scala-varargs-bug-reproduction

  2. Run sbt compile

  3. Observe the following compilation error:

[error] .../scala-varargs-bug-reproduction/scala2/src/main/scala/Main.scala:2:63: too many arguments (found 3, expected 1) for method apply: (numbers: Seq[Int] @scala.annotation.internal.Repeated): NumberPrinter in object NumberPrinter
[error]   def main(arguments: Array[String]): Unit = NumberPrinter(1, 2, 3).print()

Problem

I'd expect this to compile.

jadenPete avatar Oct 01 '25 15:10 jadenPete