dart-lang / dart-lang/language

Ability to provide constructor that forwards all arguments

Open
#493 10 comments 48 reactions 0 assignees View on GitHub
Dominant language
TeX
Stars
2.9k
Forks
239
Avg merge
2d 18h
Merged PRs (30d)
14

Description

Consider someone creating a Flutter package that extends a bunch of widgets with an extra argument, for example adding an `isEnabled` argument to every button, which changes how the `onPressed` argument gets forwarded.

Currently, if they do this, every time the superclass constructor is changed, they have to republish their package with an update. This leads to the likelihood that the package will eventually be abandoned and won't be updated (since that is work). It also means the package will only work with some versions (those that match the API the package expected).

Imagine if instead they could provide a constructor that is defined to have all the arguments of the superclass, with just a few "edits", as in:

```dart
class MySuperButton extends Button {
MySuperButton(...super, { bool isEnabled })
: super(
onPressed: isEnabled ? onPressed : null,
...super,
);
}
```

...where `...super` stands for "fill in everything from the superclass that isn't overridden here".

See also https://github.com/dart-lang/sdk/issues/22274 which is similar but doesn't involve overriding. This proposal would make that one irrelevant (it just becomes `MySuperButton(...super)` or some such).

Contributor guide

Open the contributing guide

Research direction

Start by reading issue #493 and the linked Dart SDK issue #22274 to understand the related proposals and their differences. Review the Dart language specification and existing constructor syntax before defining the feature's semantics, syntax, compatibility impact, and acceptance criteria.

Written by the indexing model from the issue text.

Assessment

Tech stack
dart
Domain
compilers
Issue type
Feature
Difficulty
5/5
Estimated time
Over a week
Activity status
Stale
Clarity
Needs clarification
Newbie friendliness
25/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.