dart-lang / dart-lang/language

Should we have generic getters?

Open
#1,622 12 comments 31 reactions 0 assignees View on GitHub
feature
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

Open the contributing 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

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.