aboutsummaryrefslogtreecommitdiff
path: root/tests/run/i1240.scala
diff options
context:
space:
mode:
Diffstat (limited to 'tests/run/i1240.scala')
-rw-r--r--tests/run/i1240.scala27
1 files changed, 27 insertions, 0 deletions
diff --git a/tests/run/i1240.scala b/tests/run/i1240.scala
new file mode 100644
index 000000000..860806ba5
--- /dev/null
+++ b/tests/run/i1240.scala
@@ -0,0 +1,27 @@
+// A tricky case of overriding behavior
+// Note: It would be acceptable if this produced an error instead.
+// Bit testing this is tricky.
+abstract class Base[T] {
+ def foo(x: T): String
+}
+
+class C[T] extends Base[T] {
+
+ def foo(x: D): String = "D foo"
+ def foo(x: T): String = "T foo"
+}
+
+object Test {
+ def main(args: Array[String]) = {
+ val b1: Base[D] = new C[D] // which of the two foo's in C overrides the one in B?
+ assert(b1.foo(new D) == "T foo")
+ val b2: Base[D] = new C[D] {}
+ // In Java, this gives an error like this:
+ // methods foo(A) from C[D] and foo(String) from C[D] are inherited with the same signature
+ // But the analogous example with `b1` compiles OK in Java.
+ assert(b2.foo(new D) == "T foo")
+ }
+}
+
+class D
+