Skip to content
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

False positive and maybe-false negative with cascade_invocations with cascaded invocations on difference references #58662

Open
Cyp opened this issue Feb 22, 2022 · 4 comments
Labels
analyzer-linter Issues with the analyzer's support for the linter package area-analyzer Use area-analyzer for Dart analyzer issues, including the analysis server and code completion. linter-false-negative linter-false-positive 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

@Cyp
Copy link

Cyp commented Feb 22, 2022

Describe the issue
False positive with cascade_invocations on different references.

Also, a bonus maybe-false negative with uncascaded invocations on equal references, if allowed to assume that the getter's return value doesn't change.

To Reproduce

const a = 1;
const b = 2;
a.bitLength
  ..abs()
  ..ceil();
b.bitLength  // “Cascade consecutive method invocations on the same reference.”, false positive.
  ..abs()
  ..ceil();
b.bitLength.abs();  // No lint, maybe-false negative.
b.bitLength.ceil();  // No lint, maybe-false negative (if assuming that `abs()` didn't change the value of `b.bitLength`).

Expected behavior
No lint (although in this very specific example, a lint about abs and ceil having no side effects would be reasonable).

Additional context
The linter seems to think a.something and b.something are the same object, which is not in general even likely to be true.

@srawlins srawlins added linter-false-positive linter-false-negative type-bug Incorrect behavior (everything from a crash to more subtle misbehavior) P2 A bug or feature request we're likely to work on labels Aug 10, 2022
@srawlins
Copy link
Member

I fixed a very very related bug in #57855 many moons ago. In that fix, I added a TODO which is basically the "false negative" half of your bug.

I just addressed the "false positive" half of this bug here: dart-lang/linter#3713.

@karabanovbs
Copy link

any updates?

@srawlins
Copy link
Member

srawlins commented Dec 6, 2022

I did try to fix this and found it extremely difficult. I mean to chat with @bwilkerson about it.

@srawlins
Copy link
Member

Quick drive by: I see in the tests for join_return_with_assignment that they may have a mechanism for this in the impl there. The unJoinablePropertyAccessReturn and joinablePropertyAccessReturn test cases demonstrate this.

@devoncarew devoncarew added analyzer-linter Issues with the analyzer's support for the linter package area-analyzer Use area-analyzer for Dart analyzer issues, including the analysis server and code completion. labels Nov 19, 2024
@devoncarew devoncarew transferred this issue from dart-lang/linter Nov 19, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
analyzer-linter Issues with the analyzer's support for the linter package area-analyzer Use area-analyzer for Dart analyzer issues, including the analysis server and code completion. linter-false-negative linter-false-positive 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

4 participants