From ba66bd47f08e1adf3d44f578452a5113948cb988 Mon Sep 17 00:00:00 2001 From: Martin Odersky Date: Thu, 2 Feb 2017 14:55:06 +1100 Subject: Fix #1501 - Check trait inheritance condition We need to check a coherence condition between the superclass of a trait and the superclass of an inheriting class or trait. --- tests/neg/i1501.scala | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) create mode 100644 tests/neg/i1501.scala (limited to 'tests/neg') diff --git a/tests/neg/i1501.scala b/tests/neg/i1501.scala new file mode 100644 index 000000000..045f2be1d --- /dev/null +++ b/tests/neg/i1501.scala @@ -0,0 +1,18 @@ +class A { + def foo: Int = 1 +} + +trait B extends A + +abstract class D { + def foo: Int +} + +class C extends D with B // error: illegal trait inheritance +trait E extends D with B // error: illegal trait inheritance + +object Test { + def main(args: Array[String]): Unit = { + println(new C().foo) + } +} -- cgit v1.2.3 From ff0921c2e588eeb6590efea057862c14f2154e99 Mon Sep 17 00:00:00 2001 From: Martin Odersky Date: Thu, 2 Feb 2017 16:38:41 +1100 Subject: Update test case --- tests/neg/i1653.scala | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'tests/neg') diff --git a/tests/neg/i1653.scala b/tests/neg/i1653.scala index ab5369e5f..f21fc7d54 100644 --- a/tests/neg/i1653.scala +++ b/tests/neg/i1653.scala @@ -1,3 +1,3 @@ trait Foo { - def foo() = new Unit with Foo // error + def foo() = new Unit with Foo // error: cannot extend final class Unit // error: illegal trait inheritance } -- cgit v1.2.3 From 0828a5275ace05ac3bcc89c3fbbced389fab7107 Mon Sep 17 00:00:00 2001 From: Martin Odersky Date: Fri, 3 Feb 2017 10:07:14 +1100 Subject: Add test scenarios --- tests/neg/i1501.scala | 10 ++++++++++ 1 file changed, 10 insertions(+) (limited to 'tests/neg') diff --git a/tests/neg/i1501.scala b/tests/neg/i1501.scala index 045f2be1d..685566403 100644 --- a/tests/neg/i1501.scala +++ b/tests/neg/i1501.scala @@ -16,3 +16,13 @@ object Test { println(new C().foo) } } + +object Test2 { + class A + class SubA(x: Int) extends A + trait TA extends A + trait TSubA extends SubA(2) // error: trait TSubA may not call constructor of class SubA + + + class Foo extends TA with TSubA // error: missing argument for parameter x of constructor SubA: +} -- cgit v1.2.3