-
Notifications
You must be signed in to change notification settings - Fork 205
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
Infer generic from callbacks #2261
Comments
Perhaps this is related to #731, because it can't infer |
This is just the way the style of inference that Dart uses (so called "local type inference", which is also used by C#, Scala, and other similar languages) works. Basically information flows down from the enclosing context, and then back up, but there is no iterative process. Here, we must choose a type for the parameter #731 does not solve this, since there are no additional parameters to flow information from. |
How does Dart determine that |
Thanks for the explanation. |
I believe it's because
Using |
The reason for the use of the greatest closure is as follows:
It is true that in this case there is a different choice which make the code work, but in general that is not true: choosing to use (e.g.) the least closure will cause other examples to fail to infer. In general, the principle that we are using is to make a choice for the type of Again, this is a heuristic choice, and in this case it results in a failed inference where a different choice would have worked. But any other heuristic choice has the same property. There are other approaches one can try to take (e.g. unification based approaches), but in a type system like Dart's, they are almost guaranteed to be undecidable (look for results around the undecidability of type inference for system F for relevant background), and if a decidable fragment is found, likely to be much more expensive to compute which is an issue for a language which is still intended to be runnable from source. I've always been somewhat interested in exploring the ideas from this paper, but realistically, I don't think it's likely to be feasible for us to do anything along these lines given the various constraints we're working under. |
Hello! I noticed that this works fine:
While this throws
The argument type 'int' can't be assigned to the parameter type 'Never'.
I'm curious what stops Dart infer the type here? I couldn't find an existing issue about this.
The text was updated successfully, but these errors were encountered: