Skip to content

Adding a lint: Extension methods crashed when called on a dynamic object #44270

@chickenblood

Description

@chickenblood

Happens on MacOSX / Linux and reproducible in DartPad.

Dart version: Based on Flutter 1.23.0-18.1.pre Dart SDK 2.10.4

Consider the following code:

class MyClass {
  void foo() => print('foo');
}

extension Bar on MyClass {
  void bar() => print('bar');
}

void main() {
  dynamic val = MyClass();
  val.foo();
  val.bar(); // crashes
}

This compiles fine, but crashes at runtime because the extension method bar() cannot be found. The compiler should either fail with an error, or better still valid code should be generated that invokes the method at runtime.

Metadata

Metadata

Assignees

No one assigned

    Labels

    area-toolsA meta category for issues that should be addressed by tooling (prefer more concrete areas).

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions