Skip to content
This repository was archived by the owner on Feb 25, 2025. It is now read-only.

Commit f0ec362

Browse files
nshahancommit-bot@chromium.org
authored andcommitted
[ddc] Use .futureValueType from CFE
The CFE FunctionNode has a new getter for the Future value type that can be used in null safe libraries. Legacy libraries will still rely on flatten to get the type of the Future. Change-Id: I54ad3bc096fdb981f7f499f2ba3ddfcb01fd97d6 Issue: dart-lang/sdk#44745 Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/185240 Reviewed-by: Johnni Winther <[email protected]> Commit-Queue: Nicholas Shahan <[email protected]>
1 parent d2bbb91 commit f0ec362

File tree

1 file changed

+7
-10
lines changed

1 file changed

+7
-10
lines changed

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

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

0 commit comments

Comments
 (0)