-
Notifications
You must be signed in to change notification settings - Fork 1.1k
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
Wrong (not in scope) type argument inserted, leading to ClassCastException #8861
Comments
The code that is supposed to prevent this by removing parameter types from the result type is at https://github.com/lampepfl/dotty/blob/d1185c3b6a31e86f724d2e1ac43b882a452ba2fa/compiler/src/dotty/tools/dotc/typer/Namer.scala#L1499-L1506 (specifically, the |
When passing down an expected result type for typing a closure body, replace any type variables by wildcards. This is needed to avoid such type variables getting constraints that are polluted with local parameters.
When passing down an expected result type for typing a closure body, replace any type variables by wildcards. This is needed to avoid such type variables getting constraints that are polluted with local parameters.
Minimized code
Output
The program crashes on the second invocation with a ClassCastException.
Expectation
The program should print "hello" twice.
(Other possible outcome,
minimalFail
may not compile not being able to infer the type to insert intovisit
).Analysis
When running dotc with
-Xprint:typer
one can see that in the case ofminimalFail
a wrong type parameter is inserted:We can see that in
minimalFail
case, visit is called with a type parametervi.A
which is not even in scope at the time (it is an argument of a lambda that will follow).As this argument is not in scope, we don't know if
vi
could have been correctly instantiated, thus we get the unsound type judgementc.A =:= vi.A =:= Int
which is broken when we callminimalFail
with aStrV
value, because there we havec.A =:= String
, leading toString =:= Int
and a runtime error.The text was updated successfully, but these errors were encountered: