« Return to Thread: [scala] Unsoundness in overriding methods with higher-order type parameters?

[scala] Unsoundness in overriding methods with higher-order type parameters?

by nikov :: Rate this Message:

Reply to Author | View in Thread

Hi,

Consider the following code:

//////////////////////////////////////////////////
trait A {
  def f[T[_]](x : T[Int]) : T[Any]
}

class B extends A {
  def f[T[+_]](x : T[Int]) : T[Any] = x
}

class P[Y](var y : Y)
//////////////////////////////////////////////////

It accepted by the Scala 2.7.5 compiler without any errors. But is
seems unsound, because then we can write (new B:A).f[P](new
P[Int](1)), and nonvariant P[Int] is coerced to P[Any].

Thanks,
Vladimir

 « Return to Thread: [scala] Unsoundness in overriding methods with higher-order type parameters?