Skip to content

Commit f5743e6

Browse files
nshahancommit-bot@chromium.org
authored andcommitted
[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: #44745 Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/181303 Commit-Queue: Nicholas Shahan <[email protected]> Reviewed-by: Sigmund Cherem <[email protected]> Reviewed-by: Mark Zhou <[email protected]>
1 parent 6b3abe0 commit f5743e6

File tree

1 file changed

+8
-3
lines changed

1 file changed

+8
-3
lines changed

pkg/dev_compiler/lib/src/kernel/compiler.dart

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3316,10 +3316,15 @@ class ProgramCompiler extends ComputeOnceConstantVisitor<js_ast.Expression>
33163316
// In the body of an `async`, `await` is generated simply as `yield`.
33173317
var gen = emitGeneratorFn((_) => []);
33183318
// Return type of an async body is `Future<flatten(T)>`, where T is the
3319-
// declared return type.
3320-
var returnType = _types.flatten(function
3319+
// declared return type, unless T is Object. In that case the Object refers
3320+
// to a return type of `Future<Object?>`.
3321+
// TODO(nshahan) Use the Future type value when available on a FunctionNode.
3322+
var declaredReturnType = function
33213323
.computeThisFunctionType(_currentLibrary.nonNullable)
3322-
.returnType);
3324+
.returnType;
3325+
var returnType = _coreTypes.isObject(declaredReturnType)
3326+
? _coreTypes.objectNullableRawType
3327+
: _types.flatten(declaredReturnType);
33233328
return js.call('#.async(#, #)',
33243329
[emitLibraryName(_coreTypes.asyncLibrary), _emitType(returnType), gen]);
33253330
}

0 commit comments

Comments
 (0)