Skip to content

Commit c56bcf5

Browse files
committed
Don't abbreviate tuple bindings if right-hand-side is named
We need to go through an explicit pattern match to drop the names.
1 parent 123ee93 commit c56bcf5

File tree

4 files changed

+38
-28
lines changed

4 files changed

+38
-28
lines changed

compiler/src/dotty/tools/dotc/ast/Desugar.scala

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1254,8 +1254,9 @@ object desugar {
12541254
pats.forall(isVarPattern)
12551255
case _ => false
12561256
}
1257+
12571258
val isMatchingTuple: Tree => Boolean = {
1258-
case Tuple(es) => isTuplePattern(es.length)
1259+
case Tuple(es) => isTuplePattern(es.length) && !hasNamedArg(es)
12591260
case _ => false
12601261
}
12611262

tests/pos/named-tuples.check

Lines changed: 0 additions & 10 deletions
This file was deleted.

tests/run/fieldsOf.check

Lines changed: 0 additions & 17 deletions
This file was deleted.

tests/run/named-patmatch.scala

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
import annotation.experimental
2+
import language.experimental.namedTuples
3+
4+
@main def Test =
5+
locally:
6+
val (x = x, y = y) = (x = 11, y = 22)
7+
assert(x == 11 && y == 22)
8+
9+
locally:
10+
val (x = a, y = b) = (x = 1, y = 2)
11+
assert(a == 1 && b == 2)
12+
13+
locally:
14+
val (x = a, y = b) = (x = 1, y = 2)
15+
assert(a == 1 && b == 2)
16+
17+
locally:
18+
val (x, y) = (x = 1, y = 2)
19+
assert(x == 1 && y == 2)
20+
21+
locally:
22+
val (a, b) = (x = 1, y = 2)
23+
assert(a == 1 && b == 2)
24+
25+
(x = 1, y = 2) match
26+
case (x = x, y = y) => assert(x == 1 && y == 2)
27+
28+
(x = 1, y = 2) match
29+
case (x, y) => assert(x == 1 && y == 2)
30+
31+
(x = 1, y = 2) match
32+
case (a, b) => assert(a == 1 && b == 2)
33+
34+
35+
36+

0 commit comments

Comments
 (0)