aboutsummaryrefslogblamecommitdiff
path: root/tests/neg/unions.scala
blob: 099a628c93c12bbc9a671bc51d1b2b3007b2fba5 (plain) (tree)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18

















                                           



                            









                                                       
object unions {

  class A {
    def f: String = "abc"

    def g(x: Int): Int = x
    def g(x: Double): Double = x
  }

  class B {
    def f: String = "bcd"

    def g(x: Int) = -x
    def g(x: Double): Double = -x
  }

  val x: A | B = if (true) new A else new B
  def y: B | A = if (true) new A else new B
  println(x.f)  // error
  println(x.g(2)) // error
  println(y.f) // error
  println(y.g(1.0)) // error

  class C {
    private def foo = 0
    class D extends C {
      private def foo = 1
      def test(cd: C | D, dc: D | C) = (cd.foo, dc.foo)
    }
  }

}