class Outter {
type Inner = Either[Int, String]
def f(x: this.Inner) = 1
}
val o = new Outter
val someLeft = Left(1)
o.f(someLeft)
tried at the REPL:
scala> :load Learn.scala
Loading Learn.scala...
defined class Outter
o: Outter = Outter@28037ced
someLeft: scala.util.Left[Int,Nothing] = Left(1)
res0: Int = 1
Which confuses the hell out of me as Outter.f()
has an explicit path-dependent type argument (x: this.Inner
) which means only those Left
s (or Right
s) that are (a sub-type of) o.Inner
are allowed and not just any Left[Int,_]
or Right[Int,_]
. I expect to see a type mismatch error along the lines :
Required o.Inner
, Found Left[Int,Nothing]
.
But it just compiles fine! What am I (badly) missing here ?