Skip to content

Sequence arg in interpolation is rejected #14564

Closed
@som-snytt

Description

@som-snytt

Compiler version

3.1.1

Minimized code

  ~ scala
Welcome to Scala 3.1.1 (17.0.2, Java OpenJDK 64-Bit Server VM).
Type in expressions for evaluation. Or try :help.

scala> extension (sc: StringContext) def sum(xs: Int*): String = xs.sum.toString
def sum(sc: StringContext)(xs: Int*): String

scala> sum"${ List(42)* }"
-- Error: ---------------------------------------------------------------------------------------------------------------------------------------
1 |sum"${ List(42)* }"
  |       ^^^^^^^^
  |       postfix operator `*` needs to be enabled
  |       by making the implicit value scala.language.postfixOps visible.
  |       ----
  |       This can be achieved by adding the import clause 'import scala.language.postfixOps'
  |       or by setting the compiler option -language:postfixOps.
  |       See the Scaladoc for value scala.language.postfixOps for a discussion
  |       why the feature needs to be explicitly enabled.
1 error found

scala> sum"${ List(42): _* }"
-- [E031] Syntax Error: -------------------------------------------------------------------------------------------------------------------------
1 |sum"${ List(42): _* }"
  |                 ^
  |                 * can be used only for last argument

longer explanation available when compiling with `-explain`

Output

DNC

Expectation

  ~ scala
Welcome to Scala 2.13.8 (OpenJDK 64-Bit Server VM, Java 17.0.2).
Type in expressions for evaluation. Or try :help.

scala> implicit class sum(val sc: StringContext) { def sum(xs: Int*) = xs.sum.toString }
class sum

scala> sum"${ List(42): _* }"
val res0: String = 42

Metadata

Metadata

Assignees

No one assigned

    Labels

    area:desugarDesugaring happens after parsing but before typing, see desugar.scalaarea:parseritype:bug

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions