[ddc] Change ! failure to a throw TypeError

Fixes test failures in language/unsorted/inv_cse_licm_test

Change-Id: If8df024d0128568e1f65463d4a82fa593b5a6a1d
Fixes: https://github.com/dart-lang/sdk/issues/42443
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/153481
Reviewed-by: Mark Zhou <markzipan@google.com>
Commit-Queue: Nicholas Shahan <nshahan@google.com>
This commit is contained in:
Nicholas Shahan 2020-07-10 17:42:55 +00:00 committed by commit-bot@chromium.org
parent 68612120df
commit cf57f882ca
2 changed files with 21 additions and 7 deletions

View file

@ -5212,8 +5212,9 @@ class ProgramCompiler extends ComputeOnceConstantVisitor<js_ast.Expression>
@override
js_ast.Expression visitNullCheck(NullCheck node) {
var expr = node.operand;
var jsExpr = _visitExpression(expr);
// If the expression is non-nullable already, this is a no-op.
return isNullable(expr) ? notNull(expr) : _visitExpression(expr);
return isNullable(expr) ? runtimeCall('nullCheck(#)', [jsExpr]) : jsExpr;
}
@override

View file

@ -474,7 +474,9 @@ asInt(obj) {
asNullableInt(obj) => obj == null ? null : asInt(obj);
/// Checks that `x` is not null or undefined.
/// Checks for null or undefined and returns [x].
///
/// Throws [NoSuchMethodError] when it is null or undefined.
//
// TODO(jmesserly): inline this, either by generating it as a function into
// the module, or via some other pattern such as:
@ -487,12 +489,13 @@ _notNull(x) {
return x;
}
/// Checks that `x` is not null or undefined.
/// Checks for null or undefined and returns [x].
///
/// Unlike `_notNull`, this throws a `CastError` (under strict checking)
/// or emits a runtime warning (otherwise). This is only used by the
/// compiler when casting from nullable to non-nullable variants of the
/// same type.
/// Throws a [TypeError] when [x] is null or undefined (under sound null safety
/// mode) or emits a runtime warning (otherwise).
///
/// This is only used by the compiler when casting from nullable to non-nullable
/// variants of the same type.
nullCast(x, type) {
if (x == null) {
if (!strictNullSafety) {
@ -504,6 +507,16 @@ nullCast(x, type) {
return x;
}
/// Checks for null or undefined and returns [x].
///
/// Throws a [TypeError] when [x] is null or undefined.
///
/// This is only used by the compiler for the runtime null check operator `!`.
nullCheck(x) {
if (x == null) throw TypeErrorImpl("Unexpected null value.");
return x;
}
/// The global constant map table.
final constantMaps = JS<Object>('!', 'new Map()');