Skip to content

Bogus invariant_booleans analyzer warning #57551

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

Closed
apwilson opened this issue Apr 20, 2017 · 3 comments
Closed

Bogus invariant_booleans analyzer warning #57551

apwilson opened this issue Apr 20, 2017 · 3 comments
Assignees
Labels
devexp-linter Issues with the analyzer's support for the linter package legacy-area-analyzer Use area-devexp instead. linter-false-positive P4 type-bug Incorrect behavior (everything from a crash to more subtle misbehavior)

Comments

@apwilson
Copy link
Contributor

This code has an analyzer warning that's bogus imo.

enum _Foo { x, y, z }

///
class Baz {
  final double _a;
  final double _b;

  ///
  Baz(this._a, this._b);
  bool get _isHorizontal => _a == _b;

  ///
  bool doSomething(_Foo foo) {
    switch (foo) {
      case _Foo.x:
        if (_isHorizontal) {
          return false;
        }
        break;
      case _Foo.y:
        if (_isHorizontal) {
          return false;
        }
        break;
      case _Foo.z:
      default:
        break;
    }
    return true;
  }
}
@srawlins
Copy link
Member

srawlins commented Dec 5, 2018

I can recreate this. I'll even show where the error is:

$ dart bin/linter.dart --rules invariant_booleans 29407.dart 
/Users/srawlins/code/dart-linter/29407.dart 21:13 [lint] Conditions should not unconditionally evaluate to `true` or to `false`. verify: _isHorizontal.
        if (_isHorizontal) {
            ^^^^^^^^^^^^^

1 file analyzed, 1 issue found, in 1427 ms.

No idea why the lint rule would complain about the second if (_isHorizontal) but not the first...

@srawlins srawlins transferred this issue from dart-lang/sdk Dec 2, 2019
@jamesderlin
Copy link
Contributor

This looks rather similar to #57601 (multiple switch cases with a repeated condition).

@pq pq added type-bug Incorrect behavior (everything from a crash to more subtle misbehavior) linter-false-positive labels Dec 23, 2020
@srawlins srawlins added the P4 label Sep 21, 2022
@srawlins
Copy link
Member

We've deprecated invariant_booleans and will not be fixing correctness bugs going forward.

@devoncarew devoncarew added devexp-linter Issues with the analyzer's support for the linter package legacy-area-analyzer Use area-devexp instead. labels Nov 18, 2024
@devoncarew devoncarew transferred this issue from dart-archive/linter Nov 18, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
devexp-linter Issues with the analyzer's support for the linter package legacy-area-analyzer Use area-devexp instead. linter-false-positive P4 type-bug Incorrect behavior (everything from a crash to more subtle misbehavior)
Projects
None yet
Development

No branches or pull requests

6 participants