Skip to content

Commit 2164bce

Browse files
bwilkersoncommit-bot@chromium.org
authored andcommitted
Add support for await expressions
Change-Id: I36c1bad75a0f6981715e621c09df1befef38061a Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/106166 Commit-Queue: Brian Wilkerson <[email protected]> Reviewed-by: Paul Berry <[email protected]>
1 parent f9dfa7c commit 2164bce

2 files changed

Lines changed: 41 additions & 1 deletion

File tree

pkg/nnbd_migration/lib/src/graph_builder.dart

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -180,7 +180,13 @@ class GraphBuilder extends GeneralizingAstVisitor<DecoratedType> {
180180

181181
@override
182182
DecoratedType visitAwaitExpression(AwaitExpression node) {
183-
throw new UnimplementedError('TODO(brianwilkerson)');
183+
var expressionType = node.expression.accept(this);
184+
// TODO(paulberry) Handle subclasses of Future.
185+
if (expressionType.type.isDartAsyncFuture ||
186+
expressionType.type.isDartAsyncFutureOr) {
187+
expressionType = expressionType.typeArguments[0];
188+
}
189+
return expressionType;
184190
}
185191

186192
@override

pkg/nnbd_migration/test/migration_visitor_test.dart

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -272,6 +272,40 @@ void f(C c, int i) {
272272
checkExpression('c.s'), decoratedTypeAnnotation('C c').node);
273273
}
274274

275+
@failingTest
276+
test_awaitExpression_future_nonNullable() async {
277+
await analyze('''
278+
Future<void> f() async {
279+
int x = await g();
280+
}
281+
Future<int> g() async => 3;
282+
''');
283+
284+
assertNoUpstreamNullability(decoratedTypeAnnotation('int').node);
285+
}
286+
287+
@failingTest
288+
test_awaitExpression_future_nullable() async {
289+
await analyze('''
290+
Future<void> f() async {
291+
int x = await g();
292+
}
293+
Future<int> g() async => null;
294+
''');
295+
296+
assertNoUpstreamNullability(decoratedTypeAnnotation('int').node);
297+
}
298+
299+
test_awaitExpression_nonFuture() async {
300+
await analyze('''
301+
Future<void> f() async {
302+
int x = await 3;
303+
}
304+
''');
305+
306+
assertNoUpstreamNullability(decoratedTypeAnnotation('int').node);
307+
}
308+
275309
test_binaryExpression_add_left_check() async {
276310
await analyze('''
277311
int f(int i, int j) => i + j;

0 commit comments

Comments
 (0)