summaryrefslogtreecommitdiff
path: root/test/files/neg/override-object-no.scala
blob: 517408886d927c381979bc97a818fa99298ff99f (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
// See also pos/override-object-yes.scala

package case1 {
  // Missing interface in overriding object
  class Bippy { def f = 1 }
  trait Bippo

  trait Foo {
    object Bar extends Bippy with Bippo { override def f = 2 }
    def f(x: Bippo)
    def g = f(Bar)
  }
  trait Foo2 extends Foo {
    override object Bar extends Bippy {  // err
      override def f = 3
    }
  }

  // type mismatch in member
  trait Quux1 { object Bar { def g = 55 } }
  trait Quux2 extends Quux1 { override object Bar { def g = "abc" } } // err

  // still can't override final objects!
  trait Quux3 { final object Bar { } }
  trait Quux4 extends Quux3 { override object Bar  } // err
}

// type parameter as-seen-from business
package case2 {
  // invariance (see pos for the covariant case)
  class Bar[T]

  class Foo[T] {
    object A extends Bar[T]
  }

  class Baz[S] extends Foo[S] {
    override object A extends Bar[S]
  }

  class P1 extends Foo[Traversable[String]]
  class P2 extends P1 {
    override object A extends Bar[List[String]]  // err
  }
}

// Both overridden and overriding members must be objects, not vals with a module type
object SI9574 {
  object Foo
  object Bar
  trait A { def x: Foo.type }
  trait B extends A { def x: Bar.type } // should not compile (SI-9574)
  trait C extends A { override object x }
  trait D { object x; def y = x }
  trait E extends D { override val x: super.x.type = y } // OK but doesn't need object subtyping exception
}