-
Notifications
You must be signed in to change notification settings - Fork 1.7k
infer constructor type arguments from values #25220
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
@kasperpeulen definitely! We can use upwards inference for constructors like we do for generic methods. Was chatting with @leafpetersen earlier this week about this. |
awesome 👍 |
BTW, a related issue is that we don't (AFAIK) do downwards inference on generic methods. Current state of the world:
|
Also map/list literals: dart-archive/dev_compiler#108 |
note, we should fix LUB first: #25802, or we're going to get strange results in some cases |
https://codereview.chromium.org/1717803003/ fixes literals. Still need constructors. |
https://codereview.chromium.org/2115173002/ fixes constructors |
* Support for trailing commas in parameter and argument lists (#26647). * Strong mode breaking change: can now infer generic type arguments from the constructor invocation arguments (#25220). BUG= [email protected] Review URL: https://codereview.chromium.org/2163503002 .
@jmesserly Not sure if I understand correctly, but it doesn't seem to work as I expected: |
@kasperpeulen the Map.from constructor (like List.from) is designed to be able to cast from one type to another, so it won't infer. var m = <dynamic, dynamic>{1: 2}
var m2 = new Map<int, int>.from(m); // allowed, casts each key/value that's an API design choice for the SDK. Inference however is supported for constructors. For example List.filled can infer from the value type. |
Would it be possible that strong mode infers the type of
otherMap
below to beMap<String, String>
Now
otherMap
has typeMap<dynamic, dynamic>
.The text was updated successfully, but these errors were encountered: