-
Notifications
You must be signed in to change notification settings - Fork 1.7k
Type inference from parameter type #37247
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
This is a good example of a case where it would have been very useful for inference to choose However, when inference has chosen the type argument In order to address the immediate problem, you could use For the broader question of why inference did not give the parameter That kind of information flow arises automatically when type inference is done using algorithm W or similar mechanisms based on unification, but type inference using unification in a language with subtyping isn't tractable, so there's a need to go into heuristics, and that hasn't been done yet for Dart. |
@leafpetersen, do you have further comments on this? I added a reference to this issue on #25490, because it's a good example to keep in mind. This issue could then be closed, marking it as a duplicate of #25490. |
With horizontal inference (added in Dart 2.18), the example is inferred as requested (so |
The problem
Consider the following example:
I would expect the Dart Analyzer to fail at
value.bar
sinceT
could be inferred tonumber
. Instead, Dart does not inferT
tonumber
, but falls back todynamic
.What are other languages doing?
Equivalent example in TypeScript:
yields error
Equivalent example in Kotlin:
yields error
https://stackoverflow.com/questions/56540905/type-inference-from-parameter-type
The text was updated successfully, but these errors were encountered: