-
Notifications
You must be signed in to change notification settings - Fork 1.7k
Open
Labels
P3A lower priority bug or feature requestA lower priority bug or feature requestarea-dart-modelFor issues related to conformance to the language spec in the parser, compilers or the CLI analyzer.For issues related to conformance to the language spec in the parser, compilers or the CLI analyzer.type-bugIncorrect behavior (everything from a crash to more subtle misbehavior)Incorrect behavior (everything from a crash to more subtle misbehavior)
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;
}
}
Metadata
Metadata
Assignees
Labels
P3A lower priority bug or feature requestA lower priority bug or feature requestarea-dart-modelFor issues related to conformance to the language spec in the parser, compilers or the CLI analyzer.For issues related to conformance to the language spec in the parser, compilers or the CLI analyzer.type-bugIncorrect behavior (everything from a crash to more subtle misbehavior)Incorrect behavior (everything from a crash to more subtle misbehavior)