From a34c90edb84b4e7ced286cc0d68b5ecac5dd0683 Mon Sep 17 00:00:00 2001 From: Nicolas Stucki Date: Wed, 23 Jan 2019 22:39:15 +0100 Subject: [PATCH 1/2] Fix #209: Add regression test --- tests/run/i209.scala | 23 +++++++++++++++++++++++ 1 file changed, 23 insertions(+) create mode 100644 tests/run/i209.scala diff --git a/tests/run/i209.scala b/tests/run/i209.scala new file mode 100644 index 000000000000..e92b3496ec8b --- /dev/null +++ b/tests/run/i209.scala @@ -0,0 +1,23 @@ +case class Foo(a: Int) { + def copy(i: Int = 9): Foo = Foo(i) +} + +case class Bar(a: Int, b: Int) { + def copy(i: Int = 4, j: Int = 6): Bar = Bar(i, j) +} + +object Test { + def main(args: Array[String]): Unit = { + val a = Foo(2) + assert(a == Foo(2)) + assert(a.copy(5) == Foo(5)) + assert(a.copy() == Foo(9)) + + val b = Bar(2, 3) + assert(b == Bar(2, 3)) + assert(b.copy(5, 7) == Bar(5, 7)) + assert(b.copy(5) == Bar(5, 6)) + assert(b.copy(j = 5) == Bar(4, 5)) + assert(b.copy() == Bar(4, 6)) + } +} From 9f68f86f93e5bceb84157b44ffd6f3e272439968 Mon Sep 17 00:00:00 2001 From: Nicolas Stucki Date: Thu, 24 Jan 2019 07:28:00 +0100 Subject: [PATCH 2/2] Add more tests for #209 --- tests/neg/i209.scala | 9 +++++++++ tests/run/i209.scala | 17 +++++++++++++++++ 2 files changed, 26 insertions(+) create mode 100644 tests/neg/i209.scala diff --git a/tests/neg/i209.scala b/tests/neg/i209.scala new file mode 100644 index 000000000000..d000766e7327 --- /dev/null +++ b/tests/neg/i209.scala @@ -0,0 +1,9 @@ + +case class Foo(a: Int) { + private def copy(i: Int): Foo = Foo(2 * i) +} + +object Test { + val foo = Foo(2) + foo.copy(3) // error +} diff --git a/tests/run/i209.scala b/tests/run/i209.scala index e92b3496ec8b..11e7c6ae6adc 100644 --- a/tests/run/i209.scala +++ b/tests/run/i209.scala @@ -6,6 +6,15 @@ case class Bar(a: Int, b: Int) { def copy(i: Int = 4, j: Int = 6): Bar = Bar(i, j) } +case class Baz(a: Int) { + def copy(i: Int): Baz = Baz(2 * i) +} + +case class PBaz(a: Int) { + private def copy(i: Int): PBaz = PBaz(2 * i) + def copy2(i: Int): PBaz = copy(i) +} + object Test { def main(args: Array[String]): Unit = { val a = Foo(2) @@ -19,5 +28,13 @@ object Test { assert(b.copy(5) == Bar(5, 6)) assert(b.copy(j = 5) == Bar(4, 5)) assert(b.copy() == Bar(4, 6)) + + val c = Baz(2) + assert(c == Baz(2)) + assert(c.copy(3) == Baz(6)) + + val d = PBaz(2) + assert(d == PBaz(2)) + assert(d.copy2(3) == PBaz(6)) } }