-
Notifications
You must be signed in to change notification settings - Fork 1.7k
Analyzer: don't infer generic function types as type parameters #33661
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
Rather than giving up whenever the inference produces a generic function type which will be used as a type argument, it might work to replace that by However, the pragmatic aspect should work as well: Would that be a helpful or a confusing behavior? It does document the subtlety of the situation when it's flagged as an inference failure, and developers will then need to fix their code (and write something like |
If I understand correctly the proposal is to add a new static error for this in the analyzer (and I would imagine also the CFE since it doesn't currently have one either). I think we need to consider this for Dart2Stable. cc @dgrove |
Edit: I completely misread the function literal tl;dr This demonstrates analyzer bugs, and a CFE bug, but inferring It is correct, as @MichaelRFairhurst says, that this demonstrates bugs in the analyzer: It shouldn't process types that are incorrect (such as those where there is a generic function type which is used as an actual type argument: main() {
var list = [<T>(T){}];
list.isEven;
} Here is the error message for that (dartanalyzer 2.0.0-dev.67.0):
Assuming that [wrong stuff deleted] Interestingly,
A printout shows that this occurs at the declaration of |
It infers main() {
var list = [<T>(T t){}];
list.isEven; // [error] The getter 'isEven' isn't defined for the class 'List<<T>(T) → Null>'.
} |
We need to have a plan for this. This code: typedef F = T Function<T>();
main() {
F x;
var f = [x];
print(f);
} Compiles with no errors on CFE and analyzer. dart2js gives no runtime errors. VM gives a runtime error. This is potentially quite breaking to fix post Dart 2. |
@jmesserly wrote:
Oops, you're right of course! Thanks for catching that one! However, I still believe that a type which contains a generic function type as an actual type argument should be considered as a compile-time error when written by the developer, and as a type which cannot be inferred (which may or may not cause inference to fail), rather than having such types inferred and propagated around during static analysis. |
Fixed the extra "it" making the title read like a grammatical error :) pending CL: https://dart-review.googlesource.com/c/sdk/+/64644 |
Split out of #33343.
These should be errors:
Doesn't look like this will be the most straightforward thing to add to the inference engine, so I'm pushing this to dart 2.1. That said, hopefully we can get to it by then.
@eernstg @leafpetersen @jmesserly
The text was updated successfully, but these errors were encountered: