-
Notifications
You must be signed in to change notification settings - Fork 1.7k
Strong mode generics - how to apply correctly #25100
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
Explicitly instantiation of generic parameters doesn't work yet. @jmesserly is hard at work getting this in place. I believe that if you make the cast in the first line be to I'm looking into the errors within the body of toUnmodifiableListView. Just one informational comment: by typing |
Ok, the issue in the body of the method is the same - no explicit instantiation yet. The error message is confusing because the type parameter to the method ( You can fix this in the short term by pulling the closure argument out into a local function with an explicit return type: this will allow inference to fill in the type on list.map for you. Also, disregard my comment above about the closure parameter - I misunderstood the types on first read, and presumably you want that to be explicitly dynamic. |
Short reproduction case of the issues to be fixed (besides supporting explicit instantiation): void foo() {
List list = null;
// [warning] e (dynamic) will need runtime check to cast to type T
list.map((e) => e);
// [hint] The argument type '(dynamic) → T' cannot be assigned to the parameter type '(dynamic) → int'
list.map((e) => 3);
} The first one suggests that we are either not fully resolving, or are resolving too late, after we instantiate The second is just a hint, and suggests that there is propagated type information that is not getting updated correctly when we infer a resolved type. |
Ah ha. Think I know what's going on here. Upward inference runs too late, so downward inference (as well as the existing propagatedType inference for lambdas) sees the uninstantiated generic type on the generic method. My explicit instantiation fix will include a fix for this. Early on, the unknown generic types will be "dynamic". |
The code below produces a few errors I don't know how to fix.
Am I doing something wrong or is this not yet supported?
Related to
The text was updated successfully, but these errors were encountered: