aboutsummaryrefslogtreecommitdiff
path: root/tests/run/double-pattern-type.scala
diff options
context:
space:
mode:
authorOlivier Blanvillain <olivier.blanvillain@gmail.com>2017-04-06 18:44:21 +0200
committerOlivier Blanvillain <olivier.blanvillain@gmail.com>2017-04-06 18:54:08 +0200
commit5bf9d2b0046b60ae9fcdc218cd190e17023b4fae (patch)
tree842c4e3df808217ddebea02199a667c7de94e44b /tests/run/double-pattern-type.scala
parent944e677f437c39d85280c388cab000b5490e4386 (diff)
downloaddotty-5bf9d2b0046b60ae9fcdc218cd190e17023b4fae.tar.gz
dotty-5bf9d2b0046b60ae9fcdc218cd190e17023b4fae.tar.bz2
dotty-5bf9d2b0046b60ae9fcdc218cd190e17023b4fae.zip
Add tests
- t7296 & case-class-23 are moved out of pending - 1938 tests productElement > 23
Diffstat (limited to 'tests/run/double-pattern-type.scala')
-rw-r--r--tests/run/double-pattern-type.scala40
1 files changed, 40 insertions, 0 deletions
diff --git a/tests/run/double-pattern-type.scala b/tests/run/double-pattern-type.scala
new file mode 100644
index 000000000..8045d173b
--- /dev/null
+++ b/tests/run/double-pattern-type.scala
@@ -0,0 +1,40 @@
+case class C1(i: String, s: Int) { def isEmpty = false; def get = ("EMPTY", -1) }
+case class C2(i: String, s: String) { def isEmpty = false; def get = (-1, -2, -3) }
+
+object Test {
+ def main(args: Array[String]): Unit = {
+ // When both Product and name based patterns with same arity are available,
+ // we follow scalac and silently use the Product one:
+
+ val c1 = C1("s", 0)
+ c1 match {
+ case C1(a, b) =>
+ assert(a == "s")
+ assert(b == 0)
+ }
+
+ // When the size differ, both are patterns become usable:
+
+ val c2 = C2("a", "b")
+ c2 match {
+ case C2(a, b) =>
+ assert(a == "a")
+ assert(b == "b")
+ }
+
+ c2 match {
+ case C2(a, b, c) =>
+ assert(a == -1)
+ assert(b == -2)
+ assert(c == -3)
+ }
+
+ // Interestingly things also compile with a single pattern, in which case
+ // the tuple returned by get is binded to `a`:
+
+ c2 match {
+ case C2(a) =>
+ assert(a == (-1, -2, -3))
+ }
+ }
+}