Add support for await expressions

Change-Id: I36c1bad75a0f6981715e621c09df1befef38061a
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/106166
Commit-Queue: Brian Wilkerson <brianwilkerson@google.com>
Reviewed-by: Paul Berry <paulberry@google.com>
This commit is contained in:
Brian Wilkerson 2019-06-17 16:58:51 +00:00 committed by commit-bot@chromium.org
parent f9dfa7cbfd
commit 2164bcefdb
2 changed files with 41 additions and 1 deletions

View file

@ -180,7 +180,13 @@ class GraphBuilder extends GeneralizingAstVisitor<DecoratedType> {
@override
DecoratedType visitAwaitExpression(AwaitExpression node) {
throw new UnimplementedError('TODO(brianwilkerson)');
var expressionType = node.expression.accept(this);
// TODO(paulberry) Handle subclasses of Future.
if (expressionType.type.isDartAsyncFuture ||
expressionType.type.isDartAsyncFutureOr) {
expressionType = expressionType.typeArguments[0];
}
return expressionType;
}
@override

View file

@ -272,6 +272,40 @@ void f(C c, int i) {
checkExpression('c.s'), decoratedTypeAnnotation('C c').node);
}
@failingTest
test_awaitExpression_future_nonNullable() async {
await analyze('''
Future<void> f() async {
int x = await g();
}
Future<int> g() async => 3;
''');
assertNoUpstreamNullability(decoratedTypeAnnotation('int').node);
}
@failingTest
test_awaitExpression_future_nullable() async {
await analyze('''
Future<void> f() async {
int x = await g();
}
Future<int> g() async => null;
''');
assertNoUpstreamNullability(decoratedTypeAnnotation('int').node);
}
test_awaitExpression_nonFuture() async {
await analyze('''
Future<void> f() async {
int x = await 3;
}
''');
assertNoUpstreamNullability(decoratedTypeAnnotation('int').node);
}
test_binaryExpression_add_left_check() async {
await analyze('''
int f(int i, int j) => i + j;