aboutsummaryrefslogtreecommitdiff
path: root/tests/run/i1240.scala
diff options
context:
space:
mode:
authorMartin Odersky <odersky@gmail.com>2016-05-02 15:56:52 +0200
committerMartin Odersky <odersky@gmail.com>2016-05-18 19:43:22 +0200
commitf722de7c6131b544345dbc6745b5d219de5831e7 (patch)
tree393a1722b5365d4304230e8c0a58e6f36ee14458 /tests/run/i1240.scala
parent48b716012bd72486dbf4a2bd3b293ef212f4addd (diff)
downloaddotty-f722de7c6131b544345dbc6745b5d219de5831e7.tar.gz
dotty-f722de7c6131b544345dbc6745b5d219de5831e7.tar.bz2
dotty-f722de7c6131b544345dbc6745b5d219de5831e7.zip
A test case for overloading/overriding interactions
This showcases a tricky interaction between overloading and overriding. See discussion of #1240 for context.
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
+