Open
Description
Repeated arguments (foo(xs: _*)
) can either be Seq or Array (Scala 2.13 deprecates passing Array to Scala methods taking repeated arguments, but allows passing both Array and Seq to Java methods, Dotty doesn't implement that deprecation currently). But quoted patterns assume that a repeated argument is a Seq:
https://github.com/lampepfl/dotty/blob/588ac1b9252802e118d080dae86f7c3756dbfee6/compiler/src/dotty/tools/dotc/typer/Typer.scala#L730
import scala.quoted._
object Macros {
inline def testSeq(): Any = ${impl('{java.util.Arrays.asList[Int](Seq(1): _*)})}
inline def testArray(): Any = ${impl('{java.util.Arrays.asList[Int](Array(1): _*)})}
private def impl(expr: Expr[Any])(using QuoteContext): Expr[Any] = expr match {
case '{ java.util.Arrays.asList[$t]($xs: _*) } =>
xs
case _ =>
'{ "FAIL" }
}
}
import Macros._
object Test {
def main(args: Array[String]): Unit = {
println(testSeq()) // "List(1)"
println(testArray()) // "FAIL"
}
}