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/pending/pos/t7296.scala | 7 ------ tests/pending/run/case-class-23.check | 2 -- tests/pending/run/case-class-23.scala | 33 ------------------------- tests/pos/t7296.scala | 7 ++++++ tests/run/1938.scala | 45 +++++++++++++++++++++++++++++++++++ tests/run/case-class-23.check | 2 ++ tests/run/case-class-23.scala | 33 +++++++++++++++++++++++++ tests/run/double-pattern-type.scala | 40 +++++++++++++++++++++++++++++++ tests/run/zero-arity-case-class.scala | 26 ++++++++++++++++++++ 9 files changed, 153 insertions(+), 42 deletions(-) delete mode 100644 tests/pending/pos/t7296.scala delete mode 100644 tests/pending/run/case-class-23.check delete mode 100644 tests/pending/run/case-class-23.scala create mode 100644 tests/pos/t7296.scala create mode 100644 tests/run/1938.scala create mode 100644 tests/run/case-class-23.check create mode 100644 tests/run/case-class-23.scala create mode 100644 tests/run/double-pattern-type.scala create mode 100644 tests/run/zero-arity-case-class.scala diff --git a/tests/pending/pos/t7296.scala b/tests/pending/pos/t7296.scala deleted file mode 100644 index fcba17c08..000000000 --- a/tests/pending/pos/t7296.scala +++ /dev/null @@ -1,7 +0,0 @@ -// Fails Ycheck -object Test { - type A = Int - // Emits the implementation restriction but then proceeds to crash - // when creating the Foo.unapply. - case class Foo(a: A, b: A, c: A, d: A, e: A, f: A, g: A, h: A, i: A, j: A, k: A, l: A, m: A, n: A, o: A, p: A, q: A, r: A, s: A, t: A, u: A, v: A, w: A, x: A, y: A, Z: A) -} diff --git a/tests/pending/run/case-class-23.check b/tests/pending/run/case-class-23.check deleted file mode 100644 index 888ed2c9e..000000000 --- a/tests/pending/run/case-class-23.check +++ /dev/null @@ -1,2 +0,0 @@ -23 -(1,23) diff --git a/tests/pending/run/case-class-23.scala b/tests/pending/run/case-class-23.scala deleted file mode 100644 index a6d78763c..000000000 --- a/tests/pending/run/case-class-23.scala +++ /dev/null @@ -1,33 +0,0 @@ -case class TwentyThree( - _1: Int, - _2: Int, - _3: Int, - _4: Int, - _5: Int, - _6: Int, - _7: Int, - _8: Int, - _9: Int, - _10: Int, - _11: Int, - _12: Int, - _13: Int, - _14: Int, - _15: Int, - _16: Int, - _17: Int, - _18: Int, - _19: Int, - _20: Int, - _21: Int, - _22: Int, - _23: Int -) - -object Test extends dotty.runtime.LegacyApp { - val x = new TwentyThree(1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23) - println(x._23) - assert(x.copy(_1 = 1) == x) - val TwentyThree(a, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, b) = x - println((a, b)) -} diff --git a/tests/pos/t7296.scala b/tests/pos/t7296.scala new file mode 100644 index 000000000..fcba17c08 --- /dev/null +++ b/tests/pos/t7296.scala @@ -0,0 +1,7 @@ +// Fails Ycheck +object Test { + type A = Int + // Emits the implementation restriction but then proceeds to crash + // when creating the Foo.unapply. + case class Foo(a: A, b: A, c: A, d: A, e: A, f: A, g: A, h: A, i: A, j: A, k: A, l: A, m: A, n: A, o: A, p: A, q: A, r: A, s: A, t: A, u: A, v: A, w: A, x: A, y: A, Z: A) +} diff --git a/tests/run/1938.scala b/tests/run/1938.scala new file mode 100644 index 000000000..95e94678d --- /dev/null +++ b/tests/run/1938.scala @@ -0,0 +1,45 @@ +case class Large( + e1: Int, + e2: Int, + e3: Int, + e4: Int, + e5: Int, + e6: Int, + e7: Int, + e8: Int, + e9: Int, + e10: Int, + e11: Int, + e12: Int, + e13: Int, + e14: Int, + e15: Int, + e16: Int, + e17: Int, + e18: Int, + e19: Int, + e20: Int, + e21: Int, + e22: Int, + e23: Int +) + +object Test { + def main(args: Array[String]): Unit = { + val l = Large(1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23) + + assert(l.productArity == 23) + + assert(l.productElement(0) == 1) + assert(l.productElement(1) == 2) + assert(l.productElement(21) == 22) + assert(l.productElement(22) == 23) + + try { + l.productElement(23) + ??? + } catch { + case e: IndexOutOfBoundsException => assert(e.getMessage == "23") + } + } +} diff --git a/tests/run/case-class-23.check b/tests/run/case-class-23.check new file mode 100644 index 000000000..888ed2c9e --- /dev/null +++ b/tests/run/case-class-23.check @@ -0,0 +1,2 @@ +23 +(1,23) diff --git a/tests/run/case-class-23.scala b/tests/run/case-class-23.scala new file mode 100644 index 000000000..a6d78763c --- /dev/null +++ b/tests/run/case-class-23.scala @@ -0,0 +1,33 @@ +case class TwentyThree( + _1: Int, + _2: Int, + _3: Int, + _4: Int, + _5: Int, + _6: Int, + _7: Int, + _8: Int, + _9: Int, + _10: Int, + _11: Int, + _12: Int, + _13: Int, + _14: Int, + _15: Int, + _16: Int, + _17: Int, + _18: Int, + _19: Int, + _20: Int, + _21: Int, + _22: Int, + _23: Int +) + +object Test extends dotty.runtime.LegacyApp { + val x = new TwentyThree(1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23) + println(x._23) + assert(x.copy(_1 = 1) == x) + val TwentyThree(a, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, b) = x + println((a, b)) +} 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)) + } + } +} diff --git a/tests/run/zero-arity-case-class.scala b/tests/run/zero-arity-case-class.scala new file mode 100644 index 000000000..de0ba4fe1 --- /dev/null +++ b/tests/run/zero-arity-case-class.scala @@ -0,0 +1,26 @@ +case class Foo() + +object Test { + def main(args: Array[String]): Unit = { + assert(Foo.unapply(Foo()) == true) + + // unapply generate by scalac are `_ != null`, + // dotty returns true in all cases + assert(Foo.unapply(null) == true) + + Foo() match { + case Foo() => () + case _ => ??? + } + + Foo() match { + case _: Foo => () + case _ => ??? + } + + (Foo(): Any) match { + case Foo() => () + case _ => ??? + } + } +} -- cgit v1.2.3