Skip to content

Bogus "Conditions should not unconditionally evaluate to "TRUE" or to "FALSE"" warning #28262

Closed
@Hixie

Description

@Hixie

This code:

enum Enum { a, b }

String test(Enum x, String s) {
  switch (x) {
    case Enum.a:
      if (s != null)
        return 'a';
      return 'b';
    case Enum.b:
      if (s != null)
        return 'c';
      return 'd';
  }
  return null;
}

void main() {
  print(test(Enum.a, ''));
}

This .analysis_options file:

linter:
  rules:
    - invariant_booleans

...results in this error:

$ dartanalyzer test.dart
Analyzing [test.dart]...
[lint] Conditions should not unconditionally evaluate to "TRUE" or to "FALSE" verify: s != null. (test.dart, line 11, col 11)
1 lint found.

Metadata

Metadata

Assignees

Labels

P2A bug or feature request we're likely to work onclosed-obsoleteClosed as the reported issue is no longer relevantdevexp-linterIssues with the analyzer's support for the linter packagelegacy-area-analyzerUse area-devexp instead.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