Skip to content

Commit 4068a47

Browse files
committed
Update docs
1 parent cb47074 commit 4068a47

File tree

3 files changed

+42
-44
lines changed

3 files changed

+42
-44
lines changed

docs/docs/reference/changed-features/vararg-patterns.md

Lines changed: 0 additions & 42 deletions
This file was deleted.
Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
---
2+
layout: doc-page
3+
title: "Vararg Splices"
4+
---
5+
6+
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.
7+
8+
```scala
9+
val arr = Array(1, 2, 3)
10+
val lst = List(0, arr*) // vararg splice argument
11+
lst match
12+
case List(0, 1, xs*) => println(xs) // binds xs to Seq(2, 3)
13+
case List(1, _*) => // wildcard pattern
14+
```
15+
16+
The old syntax for splice arguments will be phased out.
17+
18+
```scala
19+
/*!*/ val lst = List(0, arr: _*) // syntax error
20+
lst match
21+
case List(1, 2, xs @ _*) // ok, equivalent to `xs*`
22+
```
23+
24+
## Syntax
25+
26+
```
27+
ArgumentPatterns ::= ‘(’ [Patterns] ‘)’
28+
| ‘(’ [Patterns ‘,’] Pattern2 ‘*’ ‘)’
29+
30+
ParArgumentExprs ::= ‘(’ [‘using’] ExprsInParens ‘)’
31+
| ‘(’ [ExprsInParens ‘,’] PostfixExpr ‘*’ ‘)’
32+
```
33+
34+
## Compatibility considerations
35+
36+
To enable cross compilation between Scala 2 and Scala 3, the compiler will
37+
accept both the old and the new syntax. Under the `-source 3.1` setting, an error
38+
will be emitted when the old syntax is encountered.
39+
40+

docs/sidebar.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -141,8 +141,8 @@ sidebar:
141141
url: docs/reference/changed-features/overload-resolution.html
142142
- title: Match Expressions
143143
url: docs/reference/changed-features/match-syntax.html
144-
- title: Vararg Patterns
145-
url: docs/reference/changed-features/vararg-patterns.html
144+
- title: Vararg Splices
145+
url: docs/reference/changed-features/vararg-splices.html
146146
- title: Pattern Bindings
147147
url: docs/reference/changed-features/pattern-bindings.html
148148
- title: Pattern Matching

0 commit comments

Comments
 (0)