On Sat, Jun 20, 2009 at 8:23 AM, Vladimir
Reshetnikov<
v.reshetnikov@...> wrote:
> Hi,
>
> It seems that the current implementation of covariance is unsound.
> Consider this code:
>
> ///////////////////////////////////////////////
> class B {
> type X
> var x : X = _
> }
> class C[+T] {
> val s = new B { type X = T }
> }
> ///////////////////////////////////////////////
>
> It compiles without errors in Scala 2.8.0.r18050-b20090618020144, but
> then we can write:
>
> scala> val c = new C[Int]
> c: C[Int] = C@1046270
>
> scala> val c1 = c : C[Any]
> c1: C[Any] = C@1046270
>
> scala> c1.s.x = ""
>
> scala> c.s.x
> java.lang.ClassCastException: java.lang.String cannot be cast to
> java.lang.Integer
> at scala.runtime.BoxesRunTime.unboxToInt(Unknown Source)
>
>
It should not. In fact it turned out that refinements were never
tested for variance. I just fixed that, and will check it in on
Monday. Thanks for discoverig this!
Cheers
-- Martin