Skip to content

invariant_booleans false positive #34173

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

Closed
DanTup opened this issue Aug 17, 2018 · 3 comments
Closed

invariant_booleans false positive #34173

DanTup opened this issue Aug 17, 2018 · 3 comments
Labels
devexp-linter Issues with the analyzer's support for the linter package legacy-area-analyzer Use area-devexp instead. type-bug Incorrect behavior (everything from a crash to more subtle misbehavior)

Comments

@DanTup
Copy link
Collaborator

DanTup commented Aug 17, 2018

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.

@DanTup
Copy link
Collaborator Author

DanTup commented Aug 19, 2018

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.

@zoechi
Copy link
Contributor

zoechi commented Aug 19, 2018

Also similar #57535, #57601

@vsmenon vsmenon added legacy-area-analyzer Use area-devexp instead. devexp-linter Issues with the analyzer's support for the linter package labels Aug 21, 2018
@bwilkerson bwilkerson added the type-bug Incorrect behavior (everything from a crash to more subtle misbehavior) label Aug 28, 2018
@pq pq changed the title Unexpected "Conditions should not unconditionally evaluate to true or to false" invariant_booleans false positive Jan 21, 2019
@pq
Copy link
Member

pq commented Jan 21, 2019

This issue was moved to #57884

@pq pq closed this as completed Jan 21, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
devexp-linter Issues with the analyzer's support for the linter package legacy-area-analyzer Use area-devexp instead. type-bug Incorrect behavior (everything from a crash to more subtle misbehavior)
Projects
None yet
Development

No branches or pull requests

5 participants