This code:
trait Base[+K <: Option[Int]] {
val a: K = None
}
class GuaranteedA extends Base[Some[Int]] {
override val a = Some(1)
}
produces an error:
<console>:8: error: type mismatch;
found : None.type
required: K
val a: K = None
But why?
The type constraint in K
says K
must be a subtype of Option[Int]
which None
is, even when I try to val a: K = Some(0)
in Base
, the same error is produced.
I'm very confused of this behavior and have no idea why this happens, maybe you can help me?