If I do this:
object Parent {
class Inner extends Testable { type Self <: Inner }
def inner = new Inner()
}
object Child {
class Inner extends Parent.Inner { type Self <: Inner }
def inner = new Inner()
}
trait Testable {
type Self
def test[T <: Self] = {}
}
object Main {
// this works
val p: Parent.Inner = Child.inner
// this doesn't
val h = Parent.inner
h.test[Child.Inner]
}
I get this error:
error: type arguments [Child.Inner] do not conform to method test's type parameter bounds [T <: Main.h.Self]
h.test[Child.Inner]
Why does this error when I my Self type is Parent.Inner and Child.Inner <: Parent.Inner?
And if I change type Self <: Inner to type Self = Inner and then override type Self = Inner, I get this error:
overriding type Self in class Inner, which equals Parent.Inner;
type Self has incompatible type
class Inner extends Parent.Inner { override type Self = Inner }