Skip to content

Commit b8c2cd4

Browse files
nshahancommit-bot@chromium.org
authored andcommitted
[ddc] Don't emit null arg checks in sound mode
Compiled output for sound null safety mode no longer needs to check non-nullable arguments for null. They can't be null since we no longer allow mixed opt-in/out libraries when running with sound null safety. Cleanup a repeated string in the SDK. Change-Id: Ib7ae86f04660857957b4a7590bc5a7efd2c3fa04 Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/154848 Reviewed-by: Mark Zhou <[email protected]> Reviewed-by: Sigmund Cherem <[email protected]> Commit-Queue: Nicholas Shahan <[email protected]>
1 parent e75dca3 commit b8c2cd4

File tree

2 files changed

+9
-9
lines changed

2 files changed

+9
-9
lines changed

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

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3239,7 +3239,8 @@ class ProgramCompiler extends ComputeOnceConstantVisitor<js_ast.Expression>
32393239

32403240
if (_annotatedNullCheck(p.annotations)) {
32413241
body.add(_nullParameterCheck(jsParam));
3242-
} else if (_mustBeNonNullable(p.type) &&
3242+
} else if (!_options.soundNullSafety &&
3243+
_mustBeNonNullable(p.type) &&
32433244
!_annotatedNotNull(p.annotations)) {
32443245
// TODO(vsm): Remove if / when CFE does this:
32453246
// https://github.com/dart-lang/sdk/issues/40597

sdk/lib/_internal/js_dev_runtime/private/ddc_runtime/errors.dart

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -25,22 +25,21 @@ assertFailed(String? message,
2525
}
2626

2727
final _nullFailedSet = JS('!', 'new Set()');
28+
29+
String _nullFailedMessage(variableName) =>
30+
'A null value was passed into a non-nullable parameter: $variableName.';
31+
2832
// Run-time null safety assertion per:
2933
// https://github.com/dart-lang/language/blob/master/accepted/future-releases/nnbd/feature-specification.md#automatic-debug-assertion-insertion
3034
nullFailed(String? fileUri, int? line, int? column, String? variable) {
3135
if (_nonNullAsserts) {
32-
throw AssertionErrorImpl(
33-
'A null value was passed into a non-nullable parameter $variable',
34-
fileUri,
35-
line,
36-
column,
37-
'$variable != null');
36+
throw AssertionErrorImpl(_nullFailedMessage(variable), fileUri, line,
37+
column, '$variable != null');
3838
}
3939
var key = '$fileUri:$line:$column';
4040
if (!JS('!', '#.has(#)', _nullFailedSet, key)) {
4141
JS('', '#.add(#)', _nullFailedSet, key);
42-
_nullWarn(
43-
'A null value was passed into a non-nullable parameter $variable');
42+
_nullWarn(_nullFailedMessage(variable));
4443
}
4544
}
4645

0 commit comments

Comments
 (0)