-
Notifications
You must be signed in to change notification settings - Fork 1.7k
Lots of new strong-mode hints related to generic functions #25040
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
Yeah, something's going wrong there. It's interesting that those are showing up as hints and not warnings. I'll take a look today and see if I can figure out what's happening. |
Is it possible to add type annotations as comments on the calls site as well. I only saw examples of them on the function declaration site. How would they look like? I tried a few things but could't find anything that showed any effect. |
Yes, it is possible to do so. Your example would look like this: import 'dart:math' as math;
void main () {
int val = 10;
math.min/*<int>*/(10, val);
} This doesn't solve your issue though. Note also that generic methods are not yet integrated into the errors and warnings code, so you won't get all of the errors that you might expect. This may be why you are seeing those hints - a bad interaction between the implemented and unimplemented parts of this. I don't understand yet why our tests aren't catching this though. |
There seems to be a problem with using generics though prefixed identifiers. If you remove the qualification on the import and use min unprefixed, the hints go away. I'll keep looking for the root cause. |
Great, thanks for the info! |
I failed to figure out what's the difference between |
Sure. We'll write this up soon when it's ready for broader use, but since you're already experimenting, here's a quick explanation. In a method or function declaration, In a method or function invocation, In a class type declaration, constructor call, or generic method invocation, In a variable declaration, writing Example: // mapi maps List<S> to List<T> with a mapper that also takes an index.
List<dynamic /*=T*/> mapi/*<S, T>*/(List<dynamic /*=S*/> inList, /*=T*/ mapper(int i, /*=S*/ x)) {
var outList = <dynamic /*=T*/>[];
for(int i = 0; i < inList.length;i++) {
var /*=T*/ e = mapper(i,inList[i] );
outList.add(e);
}
return outList;
}```
A couple of caveats.
- This is not fully implemented yet. You won't get all of the errors and warnings you would expect.
- Inference is only partially landed. You will have to be fairly explicit with your types.
- This is not intended to be a long term solution. The syntax is chosen to make it easy to convert to the real syntax once (if) we can land that.
- Only DDC will reifiy generics using the comment syntax. For all other platforms (VM, dart2js), the comments will be ignored. |
Tanks a lot :) |
This seems to have fixed the prefixed top level function issue (the math.min example), but doesn't fix the other case. I'll keep looking into that one. |
The map example may be an interaction with inferred return types. Replacing the lambda with a local bound function eliminates the erroneous hint. |
The remaining issue here is fixed by 095310b . |
Great! Can't wait to try it :) |
I wasn't yet able to figure out how to apply generic type comments to satisfy these checks.
The text was updated successfully, but these errors were encountered: