-
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
Flow analysis. The body of while(false)...
is dead code
#60322
Comments
Flow analysis is behaving as expected (and as specified). Background: to avoid compromising compilation speed, flow analysis has been designed so that it only requires a single pass through the user's code. This means that whenever there is incoming control flow from a backwards branch, flow analysis has to perform a conservative approximation. In the example: main() {
late int n;
while (false) {
n = 42;
}
n;
} The control flow looks like this: flowchart TD
Start --> id1[late int n]
id1 --> id2@{ shape: f-circ }
id2 --> id3{"loop condition:
false"}
id3 -->|if true| id4[n = 42]
id4 --> id2
id3 -->|if false| id5[n]
id5 --> End
When flow analysis reaches the join point at the top of the Since there is incoming control flow from a backwards branch (coming from the bottom of the This all happens in spite of the fact that the loop condition is Later, when flow analysis does reach the loop condition, it uses the fact that it is As a result, when flow analysis reaches the reference to |
Thank you for the detailed explanation! |
Thanks to @eernstg for helping with finding this issue. No expected error below in either CFE or the analyzer.
Dart SDK version: 3.8.0-174.0.dev (dev) (Mon Mar 10 21:06:07 2025 -0700) on "windows_x64"
The text was updated successfully, but these errors were encountered: