mirror of
https://github.com/dart-lang/sdk
synced 2024-11-05 18:22:09 +00:00
[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:
parent
6b3abe0a98
commit
f5743e6c66
1 changed files with 8 additions and 3 deletions
|
@ -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]);
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue