From 5bf9d2b0046b60ae9fcdc218cd190e17023b4fae Mon Sep 17 00:00:00 2001 From: Olivier Blanvillain Date: Thu, 6 Apr 2017 18:44:21 +0200 Subject: Add tests - t7296 & case-class-23 are moved out of pending - 1938 tests productElement > 23 --- tests/run/double-pattern-type.scala | 40 +++++++++++++++++++++++++++++++++++++ 1 file changed, 40 insertions(+) create mode 100644 tests/run/double-pattern-type.scala (limited to 'tests/run/double-pattern-type.scala') 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)) + } + } +} -- cgit v1.2.3