Skip to content

Commit efcb8f9

Browse files
srawlinscommit-bot@chromium.org
authored andcommitted
Migrator: Do not connect return values to return types on generators
Fixes #42299 Change-Id: I07b3955907efa3007ec146f4cb4170b117b58dcf Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/151328 Reviewed-by: Paul Berry <[email protected]> Commit-Queue: Samuel Rawlins <[email protected]>
1 parent 6118481 commit efcb8f9

File tree

2 files changed

+26
-1
lines changed

2 files changed

+26
-1
lines changed

pkg/nnbd_migration/lib/src/edge_builder.dart

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1362,7 +1362,12 @@ class EdgeBuilder extends GeneralizingAstVisitor<DecoratedType>
13621362
DecoratedType visitReturnStatement(ReturnStatement node) {
13631363
DecoratedType returnType = _currentFunctionType.returnType;
13641364
Expression returnValue = node.expression;
1365-
final isAsync = node.thisOrAncestorOfType<FunctionBody>().isAsynchronous;
1365+
var functionBody = node.thisOrAncestorOfType<FunctionBody>();
1366+
if (functionBody.isGenerator) {
1367+
// Do not connect the return value to the return type.
1368+
return _dispatch(returnValue);
1369+
}
1370+
final isAsync = functionBody.isAsynchronous;
13661371
if (returnValue == null) {
13671372
var target =
13681373
NullabilityNodeTarget.text('implicit null return').withCodeRef(node);

pkg/nnbd_migration/test/edge_builder_test.dart

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6836,6 +6836,26 @@ int f() {
68366836
expect(edge.sourceNode.displayName, 'implicit null return (test.dart:2:3)');
68376837
}
68386838

6839+
Future<void> test_return_in_asyncStar() async {
6840+
await analyze('''
6841+
Stream<int> f() async* {
6842+
yield 1;
6843+
return;
6844+
}
6845+
''');
6846+
assertNoUpstreamNullability(decoratedTypeAnnotation('Stream<int>').node);
6847+
}
6848+
6849+
Future<void> test_return_in_syncStar() async {
6850+
await analyze('''
6851+
Iterable<int> f() sync* {
6852+
yield 1;
6853+
return;
6854+
}
6855+
''');
6856+
assertNoUpstreamNullability(decoratedTypeAnnotation('Iterable<int>').node);
6857+
}
6858+
68396859
Future<void> test_return_null() async {
68406860
await analyze('''
68416861
int f() {

0 commit comments

Comments
 (0)