Skip to content
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

Incorrect warning: invariant_booleans #58293

Closed
maxlapides opened this issue Dec 23, 2020 · 1 comment
Closed

Incorrect warning: invariant_booleans #58293

maxlapides opened this issue Dec 23, 2020 · 1 comment
Labels
analyzer-linter Issues with the analyzer's support for the linter package area-analyzer Use area-analyzer for Dart analyzer issues, including the analysis server and code completion.

Comments

@maxlapides
Copy link

I have an unusual algorithm I'm working on. I tried to create a smaller reproduction example for this ticket. This code is useless, but it does demonstrate the analyzer issue:

void test() {
  final a = [4, 5, 6, 7];
  var k = 0;
  for (var i = 0; i < 4; i++) {
    if (k >= a.length) break;
    while (k < a.length) {
      print(a[k]);
      k++;
    }
    k -= i + 1;
  }
}

Warning:

info: Conditions should not unconditionally evaluate to `true` or to `false`. verify: k < a.length.

The first time the while loop is executed, we can know through static analysis that k < a.length because this condition was just checked on the previous line. However, on the next iteration of the while loop, k < a.length may or may not be true.

@srawlins srawlins transferred this issue from dart-lang/sdk Dec 24, 2020
@srawlins
Copy link
Member

srawlins commented Jan 7, 2021

Duplicate of #57601

@srawlins srawlins closed this as completed Jan 7, 2021
@devoncarew devoncarew added analyzer-linter Issues with the analyzer's support for the linter package area-analyzer Use area-analyzer for Dart analyzer issues, including the analysis server and code completion. labels Nov 19, 2024
@devoncarew devoncarew transferred this issue from dart-lang/linter Nov 19, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
analyzer-linter Issues with the analyzer's support for the linter package area-analyzer Use area-analyzer for Dart analyzer issues, including the analysis server and code completion.
Projects
None yet
Development

No branches or pull requests

3 participants