-
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
Inconsistent type demoting of a template #55021
Comments
Starting with front-end here, although might be language |
@chloestefantsova Can you take a look at this? |
It looks like a case of a specified behavior that somewhat goes against the intuitive expectations. The static type of the In the case of If my analysis is correct, this is closer to a language issue than a front-end issue. @eernstg, WDYT? |
I'm not sure it's an issue, it is all working as intended! ;-) As @chloestefantsova explained, the type arguments used during the creation of various instances of For example: void main() {
List<num> xs = [1];
xs.add(1.5); // OK?
} In this example, However, we could also have said (in a hypothetical language which isn't quite Dart) "that list has its own type, we don't care what the context wants". We would then have inferred So, in general, if your program specifies an expectation about the type of an expression then type inference will try to make it so. By the way, Next, it's a well-known source of confusion that missing type arguments are provided implicitly by taking the bound (and using If you want to avoid having analyzer:
language:
strict-raw-types: true
strict-inference: true
strict-casts: true
linter:
rules:
- avoid_dynamic_calls In particular, |
I'll close this issue because it doesn't report anything that is working in a way that is unintended. @seha-bot, you're of course welcome to create a new issue if needed, here or in the language repository. |
Dart 3.3.0
Consider this snippet:
Output:
I don't think there is a valid reason for
foos1
's elements losing their type.Second example:
In the above example
bar
's type is never forgotten, buta
is demoted toFoo<dynamic>
even tho the instance is of typeFoo<int>
.The text was updated successfully, but these errors were encountered: