Skip to content

Commit 6add414

Browse files
nshahancommit-bot@chromium.org
authored andcommitted
[dartdevc] Add missing FutureOr normalization
FutureOr<Object> --> Object FutureOr<Object>? --> Object? I don't believe this to be breaking because in the current SDK nullable types do not yet exist, and we already landed the change to normalize FutureOr of a top type. Right now Object is still considered a top type. Issue: #40611 Change-Id: I83cb06db9e4bca8cb9b2c041a044904eb1080d2e Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/139031 Reviewed-by: Mark Zhou <[email protected]> Reviewed-by: Sigmund Cherem <[email protected]> Commit-Queue: Nicholas Shahan <[email protected]>
1 parent a7b8401 commit 6add414

File tree

2 files changed

+11
-2
lines changed

2 files changed

+11
-2
lines changed

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

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2577,7 +2577,14 @@ class ProgramCompiler extends ComputeOnceConstantVisitor<js_ast.Expression>
25772577
if (typeArgument is InterfaceType &&
25782578
typeArgument.classNode == _coreTypes.objectClass) {
25792579
// Normalize FutureOr of Object, Object?, Object*.
2580-
normalizedType = typeArgument;
2580+
var nullable = futureOr.nullability == Nullability.nullable ||
2581+
typeArgument.nullability == Nullability.nullable;
2582+
var legacy = futureOr.nullability == Nullability.legacy ||
2583+
typeArgument.nullability == Nullability.legacy;
2584+
var nullability = nullable
2585+
? Nullability.nullable
2586+
: legacy ? Nullability.legacy : Nullability.nonNullable;
2587+
normalizedType = typeArgument.withNullability(nullability);
25812588
} else if (typeArgument is NeverType) {
25822589
// FutureOr<Never> --> Future<Never>
25832590
normalizedType = InterfaceType(

sdk_nnbd/lib/_internal/js_dev_runtime/private/ddc_runtime/classes.dart

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -140,8 +140,10 @@ normalizeFutureOr(typeConstructor, setBaseClass) {
140140
// Normalize raw FutureOr --> dynamic
141141
if (JS<bool>('!', '# == void 0', typeArg)) return _dynamic;
142142

143-
// FutureOr<dynamic|void|Object?|Object*> --> dynamic|void|Object?|Object*
143+
// FutureOr<dynamic|void|Object?|Object*|Object> -->
144+
// dynamic|void|Object?|Object*|Object
144145
if (_isTop(typeArg) ||
146+
_equalType(typeArg, Object) ||
145147
(_jsInstanceOf(typeArg, LegacyType) &&
146148
JS<bool>('!', '#.type === #', typeArg, Object))) {
147149
return typeArg;

0 commit comments

Comments
 (0)