-
Notifications
You must be signed in to change notification settings - Fork 1.1k
Sequence arg in interpolation is rejected #14564
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
Comments
This is not allowed in Scala 2. It fails with the error |
Given that we can do extension (sc: StringContext) def sum(xs: Seq[Int]): String = xs.sum.toString
def test(xs: List[Int]) = sum"${ xs }" but not extension (sc: StringContext) def sum(xs: Int*): String = xs.sum.toString
def test = sum"${ 1, 2, 3 }" it seems natural to not allow the variable arguments in string interpolators. |
We need a better error message |
extension (sc: StringContext) def sum(xs: Int*): String = xs.sum.toString
def test1(xs: List[Int]) = sum"${ xs* }" // needs fix in desugar
def test2(xs: List[Int]) = sum"${ xs: _* }" // needs fix in parser See |
The test on Scala 2 is here I noticed the behavior backporting Scala 3 messages. I think you mean the macro expansion of
|
Strange. I tried the same example in Scastie for Scala 2.13.8 and it failed implicit class StringContextOps(val sc: StringContext) extends AnyVal {
def sum(xs: Int*): String = xs.sum.toString
}
def test = sum"${List(42,27): _*}" // error: repeated argument not allowed here See https://scastie.scala-lang.org/KP2jZBi0TkmVEA24VeOUTQ Could it be a bug in the Scala 2 repl? |
In Scala 3 the repl parser is consistent with the normal parser. |
@nicolasstucki that is a
|
Compiler version
3.1.1
Minimized code
Output
DNC
Expectation
The text was updated successfully, but these errors were encountered: