dart-lang / dart-lang/language
Propagating type parameter from generic function's argument to the function call
- Dominant language
- TeX
- Stars
- 2.9k
- Forks
- 239
- Avg merge
- 2d 18h
- Merged PRs (30d)
- 14
Description
While an object with a generic parameter preserves that type value, it is difficult to call a function passing/propagating that generic parameter. A work around is the call the function from the object. This seems quite tedious, surely there is, or can be a better way?
```
typedef GenericFunction = R Function(A args);
// in AppSetting class
R callTyped(GenericFunction fn, A args) => fn(args);
void onSetting(AppSetting setting) {
print(T);
print(setting.runtimeType);
}
void main() {
test('test', () {
for (final setting in AppSetting.values) {
onSetting(setting); // prints dynamic, AppSetting
setting.callTyped((args) => onSetting(setting as AppSetting), setting); // prints double, AppSetting
}
});
}
```
Contributor guide
Research direction
The issue names no files, tests, or entry points. Start by clarifying the proposed type-parameter propagation semantics from the example and determining the desired language behavior. Done requires an agreed design and corresponding specification and test changes, none of which are identified here.
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