aboutsummaryrefslogblamecommitdiff
path: root/tests/run/i1240.scala
blob: 7092d91314e4e19e7bf5f9537a0cceee1959022c (plain) (tree)
1
2
3
                                       

                                                                  























                                                                                                 
// A tricky case of overriding behavior
// Note: It might be acceptable if this produced an error instead.
// But 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