Open
Description
Dart SDK version: 3.5.4
If a generator function contains return
, inferenced return type becomes Iterable<T?>
/Stream<T?>
, while it should be Iterable<T>
/Stream<T>
.
example code:
void main() {
//==================== sync* ===============================
//✅ inferenced return type is Iterable<int>
withOutReturnSync() sync* {
yield 1;
}
// ❌ inferenced return type becomes `Iterable<int?>`, expect to be `Iterable<int>`
withReturnSync() sync* {
yield 1;
return;
}
//✅ manually specifying the type works fine
Iterable<int> withReturnSync2() sync* {
yield 1;
return;
}
//===================== async* =================================
//✅ inferenced return type is Stream<int>
withoutReturnASync() async* {
yield 1;
}
// ❌ inferenced return type becomes `Stream<int?>`, expect to be `Stream<int>`
withReturnASync() async* {
yield 1;
return;
}
//✅ manually specifying the type works fine
Stream<int> withReturnASync2() async* {
yield 1;
return;
}
}