Skip to content

Commit 8fe2b1d

Browse files
authored
Merge pull request #4024 from dotty-staging/fix-#3747
Fix #3861: Spec changes to extractors implemented in #3747
2 parents 7f18d53 + fe10bec commit 8fe2b1d

File tree

1 file changed

+26
-0
lines changed

1 file changed

+26
-0
lines changed

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

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,4 +18,30 @@ supported:
1818
/*!*/ case List(1, 2, xs @ _*) // syntax error
1919
/*!*/ case List(1, 2, _*) => ... // syntax error
2020

21+
Another change relates to extractors producing values with `T*` types, which can then be
22+
matched by vararg patterns. Previously, such extractors used an `unapplySeq` whereas now they use an `unapply` (in the long term, we plan to get rid of `unapplySeq` altogether, replacing all its usages with `unapply`).
23+
24+
Example: Previously, this was correct:
25+
26+
class Person(val name: String, val children: Person *)
27+
object Person {
28+
def unapplySeq(p: Person) = Some((p.name, p.children))
29+
}
30+
31+
def childCount(p: Person) = p match {
32+
case Person(_, ns @ _*) => ns.length
33+
}
34+
35+
Now, the equivalent program is written as follows:
36+
37+
class Person(val name: String, val children: Person *)
38+
object Person {
39+
def unapply(p: Person) = Some((p.name, p.children))
40+
}
41+
42+
def childCount(p: Person) = p match {
43+
case Person(_, ns : _*) => ns.length
44+
}
45+
46+
2147

0 commit comments

Comments
 (0)