Skip to content

cascade_invocations is too eager when type promotion is necessary #57970

Open
@ghost

Description

@ghost

@Hixie commented on Mar 4, 2018, 10:53 AM UTC:

Enable the cascade_invocations lint, then analyze this:

class A { }
class B extends A { void foo() { } }

void test(A x) {
  if (A is B) {
    final B b = x;
    b.foo();
  }
}

void main() { }

It says: lint • Cascade consecutive method invocations on the same reference at test.dart:7:5 • cascade_invocations

However, if you change it as suggested:

class A { }
class B extends A { void foo() { } }

void test(A x) {
  if (A is B) {
    final B b = x
      ..foo();
  }
}

void main() { }

...then now the code is no longer correct (error • The method 'foo' isn't defined for the class 'A' at test.dart:7:9 • undefined_method).

This issue was moved by pq from dart-lang/sdk#32407.

Metadata

Metadata

Assignees

No one assigned

    Labels

    P3A lower priority bug or feature requestarea-devexpFor issues related to the analysis server, IDE support, linter, `dart fix`, and diagnostic messages.customer-flutterdevexp-linterIssues with the analyzer's support for the linter packagelinter-false-positiveIssues related to lint rules that report a problem when it isn't a problem.type-bugIncorrect behavior (everything from a crash to more subtle misbehavior)

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions