-
Notifications
You must be signed in to change notification settings - Fork 1.1k
Error Overriding: incompatible types #4771
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Comments
With scalac, you can override a polymorphic def with another polymorphic def with less precise bounds: class A {
def foo[F <: Int] = {}
}
class B extends A {
override def foo[F] = {}
} I think this is OK from a soundness point of view since the variance checks out, but it's kind of inconsistent with the fact that we don't allow the same for term parameters, e.g. the following doesn't work with scalac: class A {
def foo(x: String) = {}
}
class B extends A {
override def foo(x: Any) = {}
} |
Yes, it's just (like) contravariance of functions — I wonder if the second doesn't work just because of JVM restrictions? (Not that we have a soundness proof covering this contravariance, but just because we don't have a proof regarding higher-kinded types either). |
Just like in Scala 2, we now allow an override to widen the bounds of a polymorphic type parameter (this is sound because parameters can vary contravariantly). (And just like Scala 2, we continue not allowing an overriding to widen the type of a term parameter).
Just like in Scala 2, we now allow an override to widen the bounds of a polymorphic type parameter (this is sound because parameters can vary contravariantly). (And just like Scala 2, we continue not allowing an overriding to widen the type of a term parameter).
Just like in Scala 2, we now allow an override to widen the bounds of a polymorphic type parameter (this is sound because parameters can vary contravariantly). (And just like Scala 2, we continue not allowing an overriding to widen the type of a term parameter).
Just like in Scala 2, we now allow an override to widen the bounds of a polymorphic type parameter (this is sound because parameters can vary contravariantly). (And just like Scala 2, we continue not allowing an overriding to widen the type of a term parameter).
Fix #4771: Relax overriding check for polymorphic methods
The text was updated successfully, but these errors were encountered: