Skip to content

invariant_booleans does not correctly handle switch statements #58712

@maxlapides

Description

@maxlapides

Describe the issue
It seems like invariant_booleans doesn't understand quite how switch statements work 🤔

To Reproduce

void test() {
  final segments = [];
  const label = 'hi';
  switch (label) {
    case 'hi':
      if (segments.length != 2) return;
      break;
    case 'bye':
      if (segments.length != 2) return; # invariant_booleans issue
      break;
  }
}

This code generates this warning on the first statement under case 'bye':

Conditions should not unconditionally evaluate to `true` or to `false`. verify: segments.length != 2.

Expected behavior

This code should not violate the invariant_booleans rule.

Metadata

Metadata

Assignees

No one assigned

    Labels

    devexp-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