-
Notifications
You must be signed in to change notification settings - Fork 1.7k
Flow analysis. Variable can be promoted to the type which is not subtype of its current type. #60646
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
I think |
Flow analysis is behaving in the way that's intended, but not in a way that's consistent with the spec. I consider this a bug in the spec. I'll need to come back later (hopefully with @eernstg's help) and specify this more precisely, but in essence, the rule is that an assignment first performs demotion (discarding any promotions that aren't compatible with the written type), followed by promotion to a type of interest (if possible). Here's a first attempt at specifying that a little more precisely:
*most assignments can promote to a type of interest; the only exception is the implicit assignment performed by the initialization of a final variable at its declaration site; this ensures that
Edit: So under these rules, |
Thanks, @stereotype441! Just one thing: Why wouldn't the demotion step demote |
You're absolutely right, thank you! I've fixed my comment above. |
Should we add "... if Should we add " For the second, if I have (The underlying rule would be that if |
According to the dart-lang/co19#3160 (comment) after
s = 42
assignments
should be demoted toObject?
and boths.isEven
ands.substring(0)
should be errors.cc @stereotype441
Dart SDK version: 3.9.0-63.0.dev (dev) (Sun Apr 27 17:07:04 2025 -0700) on "windows_x64"
The text was updated successfully, but these errors were encountered: