Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Introduce a shorthand syntax to reuse ancestor constructors without having to duplicate the signature #22274

Open
Hixie opened this issue Feb 4, 2015 · 2 comments
Labels
area-language Dart language related items (some items might be better tracked at github.com/dart-lang/language). core-m type-enhancement A request for a change that isn't a bug

Comments

@Hixie
Copy link
Contributor

Hixie commented Feb 4, 2015

I have an abstract class with the following constructor. It has 5 subclasses, each of which should have that exact same constructor. For reasons that I hope are obvious, I don't really want to have to write out that whole signature six times, plus 5 occurrences of referencing the superclass constructor listing all the arguments...

abstract class PointerEvent extends Event {
    PointerEvent({ bool bubbles,
                                  this.pointer,
                                  this.kind,
                                  this.x, this.y,
                                  this.dx: 0.0, this.dy: 0.0,
                                  this.buttons: 0,
                                  this.down: false,
                                  this.primary: false,
                                  this.obscured: false,
                                  this.pressure, this.minPressure, this.maxPressure,
                                  this.distance, this.minDistance, this.maxDistance,
                                  this.radiusMajor, this.radiusMinor, this.minRadius, this.maxRadius,
                                  this.orientation, this.tilt
                              }): super(bubbles: bubbles);
    // ...lots of final fields...
}

Lasse suggests allowing a shorthand syntax for declaring constructors that just redirect to the superclass:

abstract class PointerDownEvent extends PointerEvent {
    PointerDownEvent = super;
}
@sethladd
Copy link
Contributor

sethladd commented Feb 4, 2015

Removed Type-Defect label.
Added Type-Enhancement, Area-Language, Triaged labels.

@Hixie Hixie added Type-Enhancement area-language Dart language related items (some items might be better tracked at github.com/dart-lang/language). labels Feb 4, 2015
@kevmoo kevmoo added type-enhancement A request for a change that isn't a bug and removed triaged labels Mar 1, 2016
@lrhn
Copy link
Member

lrhn commented Jun 22, 2018

See also #9468, which suggests automatically forwarding generative constructors to superclass constructors if the sub-class has no constructor. It might still be valuable to forward generative constructors explicitly.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area-language Dart language related items (some items might be better tracked at github.com/dart-lang/language). core-m type-enhancement A request for a change that isn't a bug
Projects
Language Enhancement Categories
Non-Breaking And Simple
Development

No branches or pull requests

4 participants