Skip to content

Commit 9bb87f0

Browse files
committed
Add section on vararg patterns
1 parent 717b61c commit 9bb87f0

File tree

4 files changed

+31
-2
lines changed

4 files changed

+31
-2
lines changed

docs/docs/reference/changed/lazy-vals.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ title: Changed: Lazy Vals and @volatile
44
---
55

66
Lazy val initialization no longer guarantees safe publishing. This change was done
7-
to avid the performance overhead of thread synchonization because many lazy vals are only used in a single-threaded context.
7+
to avoid the performance overhead of thread synchonization because many lazy vals are only used in a single-threaded context.
88

99
To get back safe publishing you need to annotate a lazy val with `@volatile`. In
1010

@@ -14,6 +14,6 @@ it is guaranteed that readers of a lazy val will see the value of `x`
1414
once it is assigned.
1515

1616
The [ScalaFix](https://scalacenter.github.io/scalafix/) rewrite tool
17-
as well as Dotty's own `-migration` option will rewrite all normal
17+
as well as Dotty's own `-language:Scala2 -rewrite` option will rewrite all normal
1818
lazy vals to volatile ones in order to keep their semantics compatible
1919
with current Scala's.
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
---
2+
layout: doc-page
3+
title: "Vararg Patterns"
4+
---
5+
6+
The syntax of vararg patterns has changed. In the new syntax one
7+
writes varargs in patterns exactly like one writes them in
8+
expressions, using a `: _*` type annotation:
9+
10+
xs match {
11+
case List(1, 2, xs: _*) => println(xs) // binds xs
12+
case List(1, _ : _*) => // wildcard pattern
13+
}
14+
15+
The old syntax, which is shorter but less regular, is no longer
16+
supported:
17+
18+
/*!*/ case List(1, 2, xs @ _*) // syntax error
19+
/*!*/ case List(1, 2, _*) => ... // syntax error
20+
21+

docs/sidebar.yml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,8 @@ sidebar:
4747
url: docs/reference/changed/type-inference.md
4848
- title: Implicit Resolution
4949
url: docs/reference/changed/implicit-resolution.md
50+
- title: Vararg Patterns
51+
url: docs/reference/changed/vararg-patterns.md
5052
- title: Dropped Features
5153
subsection:
5254
- title: DelayedInit
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
package varargPatterns
2+
object t1 extends App {
3+
val List(1, 2, xs : _*) = List(1, 2, 3)
4+
println(xs)
5+
val List(1, 2, _ : _*) = List(1, 2, 3)
6+
}

0 commit comments

Comments
 (0)