Migration: Properly handle awaits of custom future classes.

Bug: https://b.corp.google.com/issues/200651131
Change-Id: Ia06066783a9107848f85bc234b7612a55f54c9c9
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/214069
Reviewed-by: Konstantin Shcheglov <scheglov@google.com>
Commit-Queue: Paul Berry <paulberry@google.com>
This commit is contained in:
Paul Berry 2021-09-21 20:29:07 +00:00 committed by commit-bot@chromium.org
parent bc854d6642
commit 201ee847fe
2 changed files with 26 additions and 3 deletions

View file

@ -489,9 +489,12 @@ class EdgeBuilder extends GeneralizingAstVisitor<DecoratedType>
@override
DecoratedType visitAwaitExpression(AwaitExpression node) {
var expressionType = _dispatch(node.expression)!;
// TODO(paulberry) Handle subclasses of Future.
if (expressionType.type!.isDartAsyncFuture ||
expressionType.type!.isDartAsyncFutureOr) {
var type = expressionType.type!;
if (_typeSystem.isSubtypeOf(type, typeProvider.futureDynamicType)) {
expressionType = _decoratedClassHierarchy!
.asInstanceOf(expressionType, typeProvider.futureElement)
.typeArguments[0]!;
} else if (type.isDartAsyncFutureOr) {
expressionType = expressionType.typeArguments[0]!;
}
return expressionType;

View file

@ -1601,6 +1601,26 @@ void f({required String s}) {}
await _checkSingleFileChanges(content, expected);
}
Future<void> test_custom_future() async {
var content = '''
class CustomFuture<T> implements Future<T> {
@override
noSuchMethod(Invocation invocation) => super.noSuchMethod(invocation);
}
f(CustomFuture<List<int>> x) async => (await x).first;
''';
var expected = '''
class CustomFuture<T> implements Future<T> {
@override
noSuchMethod(Invocation invocation) => super.noSuchMethod(invocation);
}
f(CustomFuture<List<int>> x) async => (await x).first;
''';
await _checkSingleFileChanges(content, expected);
}
Future<void> test_data_flow_assignment_field() async {
var content = '''
class C {