Skip to content

Commit 2923d32

Browse files
Add double-pattern-type test case
1 parent b19b134 commit 2923d32

File tree

1 file changed

+40
-0
lines changed

1 file changed

+40
-0
lines changed

tests/run/double-pattern-type.scala

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
case class C1(i: String, s: Int) { def isEmpty = false; def get = ("EMPTY", -1) }
2+
case class C2(i: String, s: String) { def isEmpty = false; def get = (-1, -2, -3) }
3+
4+
object Test {
5+
def main(args: Array[String]): Unit = {
6+
// When both Product and name based patterns with same arity are available,
7+
// we follow scalac and silently use the Product one:
8+
9+
val c1 = C1("s", 0)
10+
c1 match {
11+
case C1(a, b) =>
12+
assert(a == "s")
13+
assert(b == 0)
14+
}
15+
16+
// When the size differ, both are patterns become usable:
17+
18+
val c2 = C2("a", "b")
19+
c2 match {
20+
case C2(a, b) =>
21+
assert(a == "a")
22+
assert(b == "b")
23+
}
24+
25+
c2 match {
26+
case C2(a, b, c) =>
27+
assert(a == -1)
28+
assert(b == -2)
29+
assert(b == -3)
30+
}
31+
32+
// Interestingly things also compile with a single pattern, in which case
33+
// the tuple returned by get is binded to `a`:
34+
35+
c2 match {
36+
case C2(a) =>
37+
assert(a == (-1, -2, -3))
38+
}
39+
}
40+
}

0 commit comments

Comments
 (0)