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 positives of cascade_invocations when there are implicit downcast assignments #57626

Closed
yyoon opened this issue Sep 27, 2017 · 6 comments
Closed
Assignees
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-positive type-bug Incorrect behavior (everything from a crash to more subtle misbehavior)

Comments

@yyoon
Copy link
Contributor

yyoon commented Sep 27, 2017

Here's an example snippet.

class Foo {}

class Bar extends Foo {
  void bar() {}
}

void baz(Foo foo) {
  Bar bar = foo;
  bar.bar();      // This line is reported by cascade_invocations rule
}

In this case, we can't simply change this to Bar bar = foo..bar(); because foo is not of type Bar until it is assigned to bar variable using implicit downcast. The only reasonable way I found to get around this issue is to suppress the warning with an // ignore: cascade_invocations comment, but maybe I missed something.

@alexeieleusis alexeieleusis self-assigned this Sep 27, 2017
@a14n
Copy link
Contributor

a14n commented Sep 28, 2017

an other workaround (foo as Bar).bar()

@yyoon
Copy link
Contributor Author

yyoon commented Sep 28, 2017

Yes, that works. Although we have avoid_as turned on as well, so it's not an option for us.

@zoechi
Copy link
Contributor

zoechi commented Sep 29, 2017

Is there still a good reason for avoid_as?
I thought that was for performance reasons that are no longer relevant.

update: #34582

@asashour
Copy link
Contributor

The case is not compilable, for line

Bar bar = foo;

A value of type 'Foo' can't be assigned to a variable of type 'Bar'. (Documentation)
Try changing the type of the variable, or casting the right-hand type to 'Bar'.

@bwilkerson
Copy link
Member

The original example was written prior to null safety. After null safely there would need to be either an explicit cast or a type test.

I suspect that we can close this issue.

@pq
Copy link
Member

pq commented Jul 29, 2021

I agree. I'm guessing there's a host of issues like this.

@srawlins srawlins closed this as completed Sep 3, 2022
@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 18, 2024
@devoncarew devoncarew transferred this issue from dart-lang/linter Nov 18, 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-positive type-bug Incorrect behavior (everything from a crash to more subtle misbehavior)
Projects
None yet
Development

No branches or pull requests

9 participants