Skip to content

Allow sub-class methods to make superclass method parameters optional. #2824

Closed
@lrhn

Description

@lrhn

If you have a class A:
 class A{
  foo(int a, int b) {}
 }
please make it possible to specialize this by making some parameters optional, e.g.:
 class B extends A {
  foo(int a, [int bar]) {}
 }
(ditto for interfaces).

This is a safe generalization of the superclass interface, since all calls to the superclass method are still valid for the subclass.

It also allows a unified implementation of different interfaces, e.g.,
  interface I {
    foo(int a, int b);
  }
  interface J {
    foo(String v);
  }
  class Unifier implements I,J {
    foo(Object x, [int bar]) {]
  }
This is currently not possible, because for one function type to be a subtype of another, they need to have the same number of non-optional arguments.

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-duplicateClosed in favor of an existing reporttype-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