From f5743e6c66d8cf4460bc1e09454d1130827f46b3 Mon Sep 17 00:00:00 2001 From: Nicholas Shahan Date: Wed, 27 Jan 2021 18:17:40 +0000 Subject: [PATCH] [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 Reviewed-by: Sigmund Cherem Reviewed-by: Mark Zhou --- pkg/dev_compiler/lib/src/kernel/compiler.dart | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/pkg/dev_compiler/lib/src/kernel/compiler.dart b/pkg/dev_compiler/lib/src/kernel/compiler.dart index db638dca9d8..1fee87eaa4d 100644 --- a/pkg/dev_compiler/lib/src/kernel/compiler.dart +++ b/pkg/dev_compiler/lib/src/kernel/compiler.dart @@ -3316,10 +3316,15 @@ class ProgramCompiler extends ComputeOnceConstantVisitor // In the body of an `async`, `await` is generated simply as `yield`. var gen = emitGeneratorFn((_) => []); // Return type of an async body is `Future`, 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`. + // 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]); }