You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
classAclassBextendsAobjectTest {
valf1:A=>Any= a => a
// This compilesvalf2:B=>Any= f1
valf3: (a: A) =>Any= a => a
// But this doesn'tvalf4: (a: B) =>Any= f3
}
In particular note (v1: A): Any <:< (a: B): Any = false, this makes sense because when overriding a method in Scala, refining its term parameters contravariantly is not allowed, but dependent function types are encoded with a refined apply method and this is not the behavior we want for them. It seems like we need some special-casing of dependent methods here. @odersky WDYT ?
The text was updated successfully, but these errors were encountered:
That's a language enhancement, not a bug. Dependent function types are specified to be refinements of plain function types, which implies they are non-variant in their parameters. Changing this would require a different spec.
For example:
Running with
-explain-types
we get:In particular note
(v1: A): Any <:< (a: B): Any = false
, this makes sense because when overriding a method in Scala, refining its term parameters contravariantly is not allowed, but dependent function types are encoded with a refinedapply
method and this is not the behavior we want for them. It seems like we need some special-casing of dependent methods here. @odersky WDYT ?The text was updated successfully, but these errors were encountered: