-
Notifications
You must be signed in to change notification settings - Fork 1.7k
Generic method prototype syntax doesn't map well to checked mode #25637
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
EDIT: see my comment below for a TL;DR So this was (sort of) by design. Or at least, that's been the conclusion when I raised this issue a few times in the past. Currently, generic methods attempt to cohere with the future spec language (let's call it "Dart 2.0"). We're assuming that Dart will implement generic methods (in all modes), and once it does, everything will be golden. Also, we assume that in the implementation too. So the comment form was implemented in a very easy-to-rip out way in the scanner/parser. But if we don't want to wait, then we can tackle this. Hopefully we don't sink too much time, as it may very well be throw-away code. By far the most egregious hole is you can actually replace a type anywhere in your code :). So you can write Other issues: (We also instantiate the method using the upper bound (here |
Notes from discussion with @vsmenon:
CC @leafpetersen :) |
Oops, this won't work. We can't regress min/max: num/*=T*/ min/*<T extends num>*/(num/*=T*/ x, num/*=T*/ y); So we'd need to know the difference between a type annotation grammar location and a reified type position. Not sure if the parser has that much information, but maybe it does. This is related to restricting |
Updated the docs to warn users about this pitfall and encourage using |
The following is adapted from dart-archive/dev_compiler#433
This code checks under strong mode, but fails in checked mode:
with the following error on the VM:
In general, allowing
A /*=T*/
whereA != dynamic
in any place a type is reified is dangerous and may lead to inconsistencies as above. Note, if the programmer wrotenew List<dynamic /*=T*/>()
(ornew List/*<T>*/()
), there would be no problems.The text was updated successfully, but these errors were encountered: