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

The lint invariant_booleans is confused inside a switch statement. #27

Open
bsutton opened this issue Dec 21, 2020 · 1 comment
Open

Comments

@bsutton
Copy link

bsutton commented Dec 21, 2020

When using lint 1.5.1

In the following switch statement there are two cases that both check if char = ' '.

The lint incorrectly marks the second test as invariant_booleans as it sees the if char = ' ' in the first case and assume that the test protects the second case from having a space.

If you change the first char = ' ' in the first case to anything else the warning goes away.

The lint should not fire in this scenario.

 enum _ParseState { starting, inQuote, inWord }

  /// parses the given command breaking them done into words
void _parse2(String commandLine) {
    var state = _ParseState.starting;

    for (var i = 0; i < commandLine.length; i++) {
      final char = commandLine[i];

      switch (state) {
        case _ParseState.starting:
          if (char == ' ') {
            break;
          }
          break;

        case _ParseState.inWord:
          if (char == ' ')
          {
            break;
          }
      }
    }
  }
@triallax
Copy link

triallax commented Dec 11, 2021

I don't think this is an issue with lint itself; it should probably be reported in https://github.com/dart-lang/linter or https://github.com/dart-lang/sdk (not sure which one), if somebody hasn't already done so.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants