dart-lang / dart-lang/language

Callable extensions can be invoked but cannot be passed as parameters.

Open
#2,046 1 comment 0 reactions 0 assignees View on GitHub
request
Dominant language
TeX
Stars
2.9k
Forks
239
Avg merge
2d 18h
Merged PRs (30d)
14

Description

Callable extensions can be invoked but not passed as parameters. In the following example, I create an extension on `List` that implements the callable API. This allows `List`'s to be invoked like functions which works as expected in `exampleMain()`. However, even with this extension, `List` type variables cannot be passed as `List Function(int)` type parameters. See the last line of `exampleMain()`.
```
extension on List {
List call(int maxLength) {
return this;
}
}

void someFunc(List Function(int) getList) {
// Do something
}

void exampleMain(List Function(int) getList) {
List someList = [];
List theSameList = someList(50); // Okay
someFunc(someList); // 'List' can't be assigned ... to 'List Function(int)'
}
```
It might break something that I'm not thinking of, but in the above example it feels like `someList` should be able to be passed to `someFunc()`.

Contributor guide

Open the contributing guide

Research direction

Start with the example in the issue and compare invoking someList with passing it to someFunc. Review Dart's callable-extension and function-type rules to determine whether this behavior is intended and what language change would be required; done means the behavior has a settled specification or implementation direction.

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
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.