Skip to content

Strong mode allows noSuchMethod to suppress unimplemented member warnings #26863

Closed
@leafpetersen

Description

@leafpetersen

This code passes strong mode, but the second call to eatFood will fail at runtime since there is no actual eatFood method on MockCat. It's not clear that we want to just disallow this pattern entirely, but unconditionally disabling the unimplemented member warnings without doing something to make it sound is clearly the wrong thing.

class Cat {
  bool eatFood(String food) => true;
}

class MockCat implements Cat {
  dynamic noSuchMethod(Invocation invocation) {
    return 3;
  }
}

void main () {
  print((new MockCat() as dynamic).eatFood(""));
  print(new MockCat().eatFood(""));
}

Metadata

Metadata

Assignees

No one assigned

    Labels

    P2A bug or feature request we're likely to work onarea-languageDart language related items (some items might be better tracked at github.com/dart-lang/language).type-enhancementA request for a change that isn't a bug

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions