dart-lang / dart-lang/language
Returning a function expression from an async function causes type inference problems.
- Dominant language
- TeX
- Stars
- 2.9k
- Forks
- 239
- Avg merge
- 2d 18h
- Merged PRs (30d)
- 14
Description
In the following code:
```dart
typedef int IntToInt(int i);
Future b() async {
return (x) => x;
}
```
I would expect the type of `x` to be inferred as `int`. However, it is not. It is inferred as type `dynamic`.
Similar constructions using synchronous code or generators work fine, e.g.:
```dart
IntToInt a() {
return (x) => x; // x has type int
}
Iterable c() sync* {
yield (x) => x; // x has type int
}
Stream d() async* {
yield (x) => x; // x has type int
}
```
The problem is occurring because the context of the return expression is (correctly) inferred to be `FutureOr`. However, when we try to infer the type of (x) => x in this context, we see that `FutureOr` is not a function type, so we (erroneously) ignore it.
This bug currently exists only in analyzer, however I expect it will soon be replicated in front_end, so I'm filing it against both.
Contributor guide
Assessment
This issue has not been assessed yet.