-
Notifications
You must be signed in to change notification settings - Fork 1.6k
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
Why do I have to specify the parameters to fold? Why doesn't inference work? #34118
Comments
Note that in your example you don't need the If you don't specify I don't know why this is, but the following example demonstrates it more directly: void whatTypeDidIGet<T>(T arg) => print(T);
void whatTypeDidIGet2<T>(T arg, void Function(T) f) => print(T);
void whatTypeDidIGet3<T>(T arg, T Function(T) f) => print(T);
void main() {
whatTypeDidIGet(<String>[]); // List<String>
whatTypeDidIGet2(<String>[], (list) => list); // List<String>
whatTypeDidIGet3(<String>[], (list) => list); // dynamic
} |
Ah a |
I'm going to close this as WAI |
I think it's worth noting that List<String> Function(List<String>) f = (list) => list; // OK So the question is why inference does not select that solution to the given constraints? Of course, It is possible that this is an instance of the issue targeted by #25490 'Inference should flow information between arguments in a generic function call', in which case the missing bit is that the "easy argument" @leafpetersen, do you have a deeper insight on why this happens? I haven't reopened this issue because it might then quickly be reclosed as a duplicate of #25490, but I do think that the underlying topic is alive. |
@eernstg Yes. It's #25490 . |
I'm disabling implicit casts in the angular analyzer plugin, and I'm surprised I had to parameterize fold here:
Without it, I get
List<dynamic>
and then ultimately a complaint about a downcast.Isn't this inferrable based on the return type of my folding function, and the value I pass into the accumulator?
The text was updated successfully, but these errors were encountered: