dart-lang / dart-lang/language
Should we have generic getters?
- Dominant language
- TeX
- Stars
- 2.9k
- Forks
- 239
- Avg merge
- 2d 18h
- Merged PRs (30d)
- 14
Description
Given that we plan to allow `name` as an expression, do we then lift the restriction that getters cannot be generic?
This could be convenient, e.g., for the expression of "cast" getters:
```dart
extension AsExtension on Object? {
X get as => this as X;
X? get asOrNull {
var self = this;
return self is X ? self : null;
}
}
extension AsSubtypeExtension on X {
Y get asSubtype => this as Y;
}
void main() {
num? n = 1 as dynamic;
n.as.isEven;
n.asSubtype.isEven;
n.asOrNull?.isEven;
}
```
Contributor guide
Research direction
No files, tests, or entry points are named. Read the proposal and examples in issue #1622 first, then determine whether generic getters should be permitted and capture the resulting language decision or specification change as done.
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
- Quiet
- Clarity
- Mostly clear
- Newbie friendliness
- 30/100