Skip to content

Allow adding method arguments to superclass without breaking subclass #36027

@goderbauer

Description

@goderbauer

It would be nice if you could add a new argument to a method in a superclass without breaking all subclasses that override that method.

We currently have this problem in Flutter (see flutter/flutter#28206) where we have an abstract class that defines a method hitTest:

abstract class CustomPainter  {
  bool hitTest(Offset position) => null;
}

Long after this has been implemented we realized that it would be beneficial for some use cases if hitTest takes another argument of type Size:

bool hitTest(Offset position, Size size) => null;

Unfortunately, this is a breaking change and would require all of our users to update their subclasses of CustomPainter.

It would be great if this could be a non-breaking change, e.i. when hitTest(position, size) is called on a subclass that only implements hitText(position) that method is executed dropping the size argument on the floor.

Potentially, the newly introduced argument in the superclass could be marked in a way to indicate that in some subclasses this method may not take that argument.

Metadata

Metadata

Assignees

No one assigned

    Labels

    area-languageDart language related items (some items might be better tracked at github.com/dart-lang/language).closed-staleClosed as the issue or PR is assumed stale

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions