dart-lang / dart-lang/language
Allow initializing formals in setters
- Dominant language
- TeX
- Stars
- 2.9k
- Forks
- 239
- Avg merge
- 2d 18h
- Merged PRs (30d)
- 14
Description
@dmincu had this idea in an AngularDart training and I think it makes perfect sense. Not sure if this has been considered before, it seems like an easy non-breaking change to add.
This would be useful for cases where you override a setter that has a private backing store where the side-effect is not a special assignment of that backing property:
```dart
class C {
int _myInt;
set myInt(this._myInt) {
print("set myInt to $_myInt");
}
// vs
set myInt(int myInt) {
_myInt = myInt;
print("set myInt to $_myInt");
}
...
}
```
as well as cases where you override the setter only because you overrode the getter (and still want both for your field):
```dart
class C {
int _myInt;
set myInt(this._myInt); // nothing special
int get myInt {
// ...
}
}
```
I wouldn't go so far as to file these as language issues, however, I think the feature is still something that would be useful.
Contributor guide
Assessment
This issue has not been assessed yet.