Skip to content

Another bogus "Conditions should not unconditionally evaluate to "TRUE" or to "FALSE"" warning. #28967

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
ktullavik opened this issue Mar 4, 2017 · 8 comments
Labels
devexp-linter Issues with the analyzer's support for the linter package legacy-area-analyzer Use area-devexp instead. P2 A bug or feature request we're likely to work on type-bug Incorrect behavior (everything from a crash to more subtle misbehavior)

Comments

@ktullavik
Copy link

When changing a variable with unary operators, the analyser don't seem to invalidate its
assumptions - and produces false warnings.

Example, both inner conditionals in this function give bogus warnings:

    void test() {
        int b = 2;
        if (b > 0) {
            b--;
            if (b == 0) {
                return;
            }
            if (b > 0) {
              return;
            }
        }
    }

Funny enough, the warning would be appropriate for the outer conditional.
Dart SDK version: 1.22.1

@bwilkerson bwilkerson added devexp-linter Issues with the analyzer's support for the linter package legacy-area-analyzer Use area-devexp instead. P2 A bug or feature request we're likely to work on type-bug Incorrect behavior (everything from a crash to more subtle misbehavior) labels Mar 4, 2017
@bwilkerson
Copy link
Member

@alexeieleusis

@mraleph
Copy link
Member

mraleph commented Mar 4, 2017

@ktullavik b is equal to 1 after b-- so b == 0 evaluates to false and b > 0 evaluates to true unconditionally. what is bogus about the warning?

@alexeieleusis
Copy link
Contributor

These cases are indeed not considered in the rule, there is a bug reported for it and a PR out dart-archive/linter#412 should land soon.

@alexeieleusis
Copy link
Contributor

By the way, the rule does not try to infer the value of the variable, and should not warn about anything inside the outer if statement precisely because of the mutation to b.

@ktullavik
Copy link
Author

@mraleph the warning is not dependant on the value of b.

@mraleph
Copy link
Member

mraleph commented Mar 5, 2017

@ktullavik no matter which constant value you select for the initial value of b conditions like b == 0 and b > 0 would always be constant - because b value after b-- is known. They might be different depending on the constant value of b you selected, but they are nevertheless known in compile time.

Compare your example with

void test(bool x) {
  int b = x ? 2 : 1;
  if (b > 0) {
    b--;
    if (b == 0) {
        return;
    }
    if (b > 0) {
      return;
    }
  }
}

Here indeed conditions are not constant.

@ktullavik
Copy link
Author

@mraleph
Yes sorry, I should have made b unknown in the example to avoid confusion.
But it's irrelevant. The wrong analyser assumption is caused by the outer conditional,
not by the value of b.

@srawlins
Copy link
Member

This linter rule is removed.

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. P2 A bug or feature request we're likely to work on type-bug Incorrect behavior (everything from a crash to more subtle misbehavior)
Projects
None yet
Development

No branches or pull requests

5 participants