Skip to content

Scala 3 does not take arbitrary id in pattern @ binding #15784

Closed
@som-snytt

Description

@som-snytt

Compiler version

3.1.3

Minimized code

Welcome to Scala 3.1.3 (18.0.1.1, Java OpenJDK 64-Bit Server VM).
Type in expressions for evaluation. Or try :help.

scala> List(42) match { case List(h, rest @ _*) => (h, rest) case _ => }
val res0: Matchable = (42,List())

scala> List(42) match { case List(h, Rest @ _*) => (h, Rest) case _ => }
-- [E006] Not Found Error: ---------------------------------------------------------------------------------------------
1 |List(42) match { case List(h, Rest @ _*) => (h, Rest) case _ => }
  |                              ^^^^
  |                              Not found: Rest
  |
  | longer explanation available when compiling with `-explain`
-- [E006] Not Found Error: ---------------------------------------------------------------------------------------------
1 |List(42) match { case List(h, Rest @ _*) => (h, Rest) case _ => }
  |                                                ^^^^
  |                                                Not found: Rest
  |
  | longer explanation available when compiling with `-explain`
2 errors found

Expectation

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

scala> List(42) match { case List(h, rest @ _*) => (h, rest) case _ => }
val res0: Any = (42,List())

scala> List(42) match { case List(h, Rest @ _*) => (h, Rest) case _ => }
val res1: Any = (42,List())

scala> List(42) match { case List(h, Nil @ _*) => (h, Nil) case _ => }
val res2: Any = (42,List())

scala> List(42) match { case List(h, `Nil` @ _*) => (h, Nil) case _ => }
val res3: Any = (42,List())

scala> List(42) match { case List(h, `other things` @ _*) => (h, `other things`) case _ => }
val res4: Any = (42,List())

This syntax upgrade was introduced in scala/scala#4935

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions