Skip to content

Quoted patterns do not support Array repeated arguments #8680

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

Open
smarter opened this issue Apr 6, 2020 · 1 comment
Open

Quoted patterns do not support Array repeated arguments #8680

smarter opened this issue Apr 6, 2020 · 1 comment
Assignees
Labels
area:metaprogramming:quotes Issues related to quotes and splices itype:bug

Comments

@smarter
Copy link
Member

smarter commented Apr 6, 2020

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"
  }
}
@smarter
Copy link
Member Author

smarter commented Apr 6, 2020

(note that I have an open PR which interacts with this code which is how I found this: #8669)

nicolasstucki added a commit to dotty-staging/dotty that referenced this issue Apr 8, 2020
Return them as sequences
@nicolasstucki nicolasstucki added area:metaprogramming:quotes Issues related to quotes and splices and removed area:metaprogramming labels Jun 2, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area:metaprogramming:quotes Issues related to quotes and splices itype:bug
Projects
None yet
Development

No branches or pull requests

2 participants