mirror of
https://github.com/dart-lang/sdk
synced 2024-10-14 15:21:54 +00:00
[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 <markzipan@google.com> Reviewed-by: Sigmund Cherem <sigmund@google.com> Commit-Queue: Nicholas Shahan <nshahan@google.com>
This commit is contained in:
parent
e75dca3d2e
commit
b8c2cd49df
|
@ -3239,7 +3239,8 @@ class ProgramCompiler extends ComputeOnceConstantVisitor<js_ast.Expression>
|
|||
|
||||
if (_annotatedNullCheck(p.annotations)) {
|
||||
body.add(_nullParameterCheck(jsParam));
|
||||
} else if (_mustBeNonNullable(p.type) &&
|
||||
} else if (!_options.soundNullSafety &&
|
||||
_mustBeNonNullable(p.type) &&
|
||||
!_annotatedNotNull(p.annotations)) {
|
||||
// TODO(vsm): Remove if / when CFE does this:
|
||||
// https://github.com/dart-lang/sdk/issues/40597
|
||||
|
|
|
@ -25,22 +25,21 @@ assertFailed(String? message,
|
|||
}
|
||||
|
||||
final _nullFailedSet = JS('!', 'new Set()');
|
||||
|
||||
String _nullFailedMessage(variableName) =>
|
||||
'A null value was passed into a non-nullable parameter: $variableName.';
|
||||
|
||||
// Run-time null safety assertion per:
|
||||
// https://github.com/dart-lang/language/blob/master/accepted/future-releases/nnbd/feature-specification.md#automatic-debug-assertion-insertion
|
||||
nullFailed(String? fileUri, int? line, int? column, String? variable) {
|
||||
if (_nonNullAsserts) {
|
||||
throw AssertionErrorImpl(
|
||||
'A null value was passed into a non-nullable parameter $variable',
|
||||
fileUri,
|
||||
line,
|
||||
column,
|
||||
'$variable != null');
|
||||
throw AssertionErrorImpl(_nullFailedMessage(variable), fileUri, line,
|
||||
column, '$variable != null');
|
||||
}
|
||||
var key = '$fileUri:$line:$column';
|
||||
if (!JS('!', '#.has(#)', _nullFailedSet, key)) {
|
||||
JS('', '#.add(#)', _nullFailedSet, key);
|
||||
_nullWarn(
|
||||
'A null value was passed into a non-nullable parameter $variable');
|
||||
_nullWarn(_nullFailedMessage(variable));
|
||||
}
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in a new issue