Skip to content

invariant_booleans doesn't understand list manipulation (or that getters aren't invariant) #58071

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
Hixie opened this issue Dec 1, 2019 · 3 comments
Labels
devexp-linter Issues with the analyzer's support for the linter package legacy-area-analyzer Use area-devexp instead. P4 type-bug Incorrect behavior (everything from a crash to more subtle misbehavior)

Comments

@Hixie
Copy link
Contributor

Hixie commented Dec 1, 2019

Consider:

void test(List<double> x) {
  if (x.length == 1)
    return;
  x.add(1.0);
  if (x.length == 1) // bogus invariant_booleans error
    return;
  x.removeLast();
  if (x.length == 1) // bogus invariant_booleans error
    return;
}

More generally it doesn't seem to understand that getters aren't invariant:

class Test {
  int _value = 0;
  int get value	{
    _value += 1;
    return _value;
  }
}

void test(Test x) {
  if (x.value == 0)
    return;
  if (x.value == 0) // bogus invariant_booleans error
    return;
}

There's a number of other invariant_booleans errors on file.

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

srawlins commented Dec 2, 2019

The real list of invariant_booleans bugs is this list of 19.

The maturity state of this lint rule has thus been marked "experimental". http://dart-lang.github.io/linter/lints/invariant_booleans.html

@jamesderlin
Copy link
Contributor

I feel like this is equivalent to #57884. In general, it seems that the analyzer does not consider that function calls might mutate variables. Or maybe it does but assumes that local variables can't be modified?

Here's yet another example that came up when I was trying to write some string parsing code:

final list = [1, 2, 3];
final iterator = list.iterator..moveNext();
if (iterator.current == 1) {
  iterator.moveNext();
  if (iterator.current == 1) { // bogus invariant_booleans error
    print('foo');
  }
}

@pq pq added the type-bug Incorrect behavior (everything from a crash to more subtle misbehavior) label Dec 23, 2020
@srawlins srawlins added the P4 label Sep 22, 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. P4 type-bug Incorrect behavior (everything from a crash to more subtle misbehavior)
Projects
None yet
Development

No branches or pull requests

5 participants