-
Notifications
You must be signed in to change notification settings - Fork 1.1k
Union of function types leads to ClassCastException #5202
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
Variance and library free example:
|
What should this do? Frankly, a |
Honestly I don't know... But a ClassCastException should never be the expected behavior for code that doesn't contain explicit casts imho. |
A ClassCastException means that we have a soudness bug, we want this kind of things to be detected at compile-time, not runtime. Here's a minimization: class Foo[A] {
def foo(a: A): Unit = {}
}
object Test {
def main(args: Array[String]): Unit = {
val x: Foo[Int] | Foo[String] = new Foo[Int]
x.foo("") // Should not compile !
}
} Here, the compiler assigns |
Easy. The parameter should be typed as |
argForParam was overly naive for the cases where the prefix was an & or | type.
@srjd Yes, that's about it. The reason why it did not do this is and how to fix it was quite tricky, though. |
argForParam was overly naive for the cases where the prefix was an & or | type.
I don't know why or how, but:
The text was updated successfully, but these errors were encountered: