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

invariant_booleans false positive #57884

Closed
pq opened this issue Jan 21, 2019 · 5 comments
Closed

invariant_booleans false positive #57884

pq opened this issue Jan 21, 2019 · 5 comments
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. contributions-welcome Contributions welcome to help resolve this (the resolution is expected to be clear from the issue) linter-false-positive P4 type-bug Incorrect behavior (everything from a crash to more subtle misbehavior)

Comments

@pq
Copy link
Member

pq commented Jan 21, 2019

From @DanTup on August 17, 2018 17:54

This may be a dupe of #28262, #29431 or #28967 but it looks different to me so I thought it worth raising.

var hasAnError = false;
void danny() {
  if (hasAnError) {
    return;
  }
  setError();
  if (hasAnError) { // Conditions should not unconditionally evaluate to `true` or to `false`.
    return;
  }
  print('Running');
}

void setError() {
  hasAnError = true;
}

I wouldn't expect it to look through all called code to see if the variable is set, but possibly it's a bit too keen to report here.

Copied from original issue: #34173

@pq
Copy link
Member Author

pq commented Jan 21, 2019

From @DanTup on August 19, 2018 11:53

This one is even simpler:

void test(int a, int b) {
  if (a < b) {
    print('a < b');
  } else if (b < a) {
    print('b < a');
  }
}

The lint fires for the else if condition, but it's not unconditionally true or false? Strangely, if I make it b <= a (which I think would make it always true, since it's effectively an else) the lint disappears.

@pq
Copy link
Member Author

pq commented Jan 21, 2019

From @zoechi on August 19, 2018 17:45

Also similar #57535, #57601

@pq pq added type-bug Incorrect behavior (everything from a crash to more subtle misbehavior) linter-false-positive labels Jan 21, 2019
@pq
Copy link
Member Author

pq commented Jan 21, 2019

FWIW: this may be a dup; we should verify.

@pq pq added the contributions-welcome Contributions welcome to help resolve this (the resolution is expected to be clear from the issue) label Jan 21, 2019
@jakemac53
Copy link
Contributor

@grouma hit this today also (similar to the first case here), it probably shouldn't try to lint about anything other than local variables? Anything else seems like it would be to difficult to properly track down.

@srawlins
Copy link
Member

We've deprecated invariant_booleans and will not be fixing correctness bugs going forward.

@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 18, 2024
@devoncarew devoncarew transferred this issue from dart-lang/linter Nov 18, 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. contributions-welcome Contributions welcome to help resolve this (the resolution is expected to be clear from the issue) linter-false-positive P4 type-bug Incorrect behavior (everything from a crash to more subtle misbehavior)
Projects
None yet
Development

No branches or pull requests

4 participants