[ddc] Fix async methods with Object return type

The sound null safety spec includes a change in the calculation of
static types of return values in async methods. The "Future value
type" should be `Object?` when the declared return type of the
async method is `Object`.

See https://github.com/dart-lang/language/blob/master/accepted/future-releases/nnbd/feature-specification.md#the-future-value-type-of-an-asynchronous-non-generator-function

With this change,
co19/LanguageFeatures/nnbd/future_value_type_A05_t01 is now passing
in sound mode.

Change-Id: Ia7d4cb2fd57c1d2e50dbf8e59658a70124b0c8b3
Fixes: https://github.com/dart-lang/sdk/issues/44745
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/181303
Commit-Queue: Nicholas Shahan <nshahan@google.com>
Reviewed-by: Sigmund Cherem <sigmund@google.com>
Reviewed-by: Mark Zhou <markzipan@google.com>
This commit is contained in:
Nicholas Shahan 2021-01-27 18:17:40 +00:00 committed by commit-bot@chromium.org
parent 6b3abe0a98
commit f5743e6c66

View file

@ -3316,10 +3316,15 @@ class ProgramCompiler extends ComputeOnceConstantVisitor<js_ast.Expression>
// In the body of an `async`, `await` is generated simply as `yield`.
var gen = emitGeneratorFn((_) => []);
// Return type of an async body is `Future<flatten(T)>`, where T is the
// declared return type.
var returnType = _types.flatten(function
// declared return type, unless T is Object. In that case the Object refers
// to a return type of `Future<Object?>`.
// TODO(nshahan) Use the Future type value when available on a FunctionNode.
var declaredReturnType = function
.computeThisFunctionType(_currentLibrary.nonNullable)
.returnType);
.returnType;
var returnType = _coreTypes.isObject(declaredReturnType)
? _coreTypes.objectNullableRawType
: _types.flatten(declaredReturnType);
return js.call('#.async(#, #)',
[emitLibraryName(_coreTypes.asyncLibrary), _emitType(returnType), gen]);
}