The syntax of vararg splices in patterns and function arguments has changed. The new syntax uses a postfix *
, analogously to how a vararg parameter is declared.
val arr = Array(0, 1, 2, 3)
val lst = List(arr*) // vararg splice argument
lst match
case List(0, 1, xs*) => println(xs) // binds xs to Seq(2, 3)
case List(1, _*) => // wildcard pattern
The old syntax for splice arguments will be phased out.
/*!*/ val lst = List(arr: _*) // syntax error
lst match
case List(0, 1, xs @ _*) // ok, equivalent to `xs*`
Syntax
ArgumentPatterns ::= â(â [Patterns] â)â
| â(â [Patterns â,â] Pattern2 â*â â)â
ParArgumentExprs ::= â(â [âusingâ] ExprsInParens â)â
| â(â [ExprsInParens â,â] PostfixExpr â*â â)â
Compatibility considerations
To enable cross compilation between Scala 2 and Scala 3, the compiler will accept both the old and the new syntax. Under the -source future
setting, an error will be emitted when the old syntax is encountered. An automatic rewrite from old to new syntax is offered under -source future-migration
.
RetroSearch is an open source project built by @garambo | Open a GitHub Issue
Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo
HTML:
3.2
| Encoding:
UTF-8
| Version:
0.7.4