mirror of
https://github.com/dart-lang/sdk
synced 2024-10-14 14:53:37 +00:00
[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:
parent
68612120df
commit
cf57f882ca
|
@ -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
|
||||
|
|
|
@ -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()');
|
||||
|
||||
|
|
Loading…
Reference in a new issue