-
Notifications
You must be signed in to change notification settings - Fork 1.7k
Support for generic method syntax in the VM fails too aggressively in checked mode. #27437
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
It would be a rather big change in the VM to postpone the mapping of a function type parameter to a malformed type or to dynamic until the type is actually used and how it is used. It is why we map it now immediately to a malformed type, which happens to be mapped to dynamic in certain scenarios specified by the spec and that have nothing to do with generic methods. I am not currently able to help much (too long to explain, check my calendar), but here is a patch that should achieve what you want, at least for your example. @a-siva, if you do not mind trying it (you will have to adjust language test expectations) and committing it if it works, that would be awesome. Thanks. Otherwise, I will have to look at it when I am back. diff --git a/runtime/vm/parser.cc b/runtime/vm/parser.cc
|
|
As I mentioned, this would require either postponing the mapping of T to dynamic until T is used (rather a big change) or somehow marking the resolved dynamic type from T as unusable in is and as tests (also a non trivial change). I was hoping that my patch would get us there, at least most of the way. If not, I am afraid this will have to wait until I am back. |
I'm thinking that this #27460 may be a higher priority issue to follow up on. |
I agree. And this is much easier to handle this way. |
Not even arguing that this is the wrong solution, but isn't Erik's approach already fully implemented in the VM when using deferred libraries? If you replaced import 'foo.dart' deferred as x;
x.B foo(x.B tt) {
return tt;
}
main() {
x.A toto = foo(null);
print(toto as x.A);
} |
Deferred types are treated as malformed types, in all contexts. Yes, this is how we implemented function type arguments earlier. Now, we map to dynamic in all contexts. Deciding on malformed or dynamic depending on the usage complicates the implementation. That was my point. |
I missed the |
Closing this in favor of #27460 |
The support for generic method syntax added by the commit 11562f6 in response to #25869 may be too aggressive in its treatment of checked mode checks. In particular, the following program encounters a runtime error:
If this program is stored in
foo.dart
anddart --checked --generic-method-syntax foo.dart
is executed (wheredart --version
prints "...1.20.0-edge.79b682b885d770e4d073c573dff0b49fdee33d77..."), it fails with the following message (absolute path shortened to...
for readability):The approach taken in
dart2js
with--generic-method-syntax
is to omit passing actual type arguments, and then to consider formal function type parameters asdynamic
when used as a type annotation or as a type argument (to an instance creation or a type, e.g., in a type annotation), and raise a runtime error onis
andas
checks. This allows developers to run programs using generic functions/methods in checked mode, getting all the checks that they would otherwise get, and just "turning off" the checks directly involving function type parameters. I believe that a similar approach would be useful for the vm, and also that it would be useful for the vm anddart2js
to agree on the behavior.The text was updated successfully, but these errors were encountered: