Skip to content

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

@bsutton

Description

@bsutton

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;
          }
      }
    }
  }

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions