Skip to content

false positive invariant_booleans on nested if #58014

Closed
@itsnuba

Description

@itsnuba

invariant_booleans fired when im using if statement with or operation then using the same statement with and condition

To Reproduce

const a = true;
const b = false;
var text = "";
if (a || b) {
  text += "success! also : ";
  if (a && b) {
    text += "both value is true";
  } else if (a) {
    text += "only a is true";
  } else {
    text += "only b is true";
  }
} else {
  text += "error!";
}
print(text);

a && b is detected as invariant_booleans

Expected behavior
invariant_booleans should not be fired, because the condition is not redundant with previous condition

Additional context
when the inner statement is only if, without else / else if, invariant_booleans isnt fired

const a = true;
const b = false;
var text = "";
if (a || b) {
  text += "success! also : ";
  if (a && b) {
    text += "both value is true";
  }
} else {
  text += "error!";
}
print(text);

Metadata

Metadata

Assignees

No one assigned

    Labels

    P4devexp-linterIssues with the analyzer's support for the linter packagelegacy-area-analyzerUse area-devexp instead.linter-false-positiveIssues related to lint rules that report a problem when it isn't a problem.type-bugIncorrect behavior (everything from a crash to more subtle misbehavior)

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions