Skip to content

Commit 303f96d

Browse files
nshahancommit-bot@chromium.org
authored andcommitted
[ddc] Fix crash on unspecified nullability
When encountering a FutureOr<T> where both the type argument and FutureOr have unspecified nullability, compile the FutureOr type without any nullability wrappers. Change-Id: Ic822e9d5cb74864a424963d5e624c4e2bf311b33 Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/203122 Commit-Queue: Nicholas Shahan <[email protected]> Reviewed-by: Mark Zhou <[email protected]> Reviewed-by: Sigmund Cherem <[email protected]>
1 parent 0733c1f commit 303f96d

File tree

1 file changed

+14
-0
lines changed

1 file changed

+14
-0
lines changed

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

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2792,6 +2792,20 @@ class ProgramCompiler extends ComputeOnceConstantVisitor<js_ast.Expression>
27922792
// FutureOr<T?>? --> FutureOr<T?>
27932793
return futureOr.withDeclaredNullability(Nullability.nonNullable);
27942794
}
2795+
// The following is not part of the normalization spec but this is a
2796+
// convenient place to perform this change of nullability consistently. This
2797+
// only applies at compile-time and is not needed in the runtime version of
2798+
// the FutureOr normalization.
2799+
// FutureOr<T%>% --> FutureOr<T%>
2800+
//
2801+
// If the type argument has undetermined nullability the CFE propagates
2802+
// it to the FutureOr type as well. In this case we can represent the
2803+
// FutureOr type without any nullability wrappers and rely on the runtime to
2804+
// handle the nullability of the instantiated type appropriately.
2805+
if (futureOr.nullability == Nullability.undetermined &&
2806+
typeArgument.nullability == Nullability.undetermined) {
2807+
return futureOr.withDeclaredNullability(Nullability.nonNullable);
2808+
}
27952809
return futureOr;
27962810
}
27972811

0 commit comments

Comments
 (0)