diff --git a/pkg/dev_compiler/lib/src/kernel/compiler.dart b/pkg/dev_compiler/lib/src/kernel/compiler.dart index 23cc2bae20c..0801c1cd03e 100644 --- a/pkg/dev_compiler/lib/src/kernel/compiler.dart +++ b/pkg/dev_compiler/lib/src/kernel/compiler.dart @@ -3239,7 +3239,8 @@ class ProgramCompiler extends ComputeOnceConstantVisitor 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 diff --git a/sdk/lib/_internal/js_dev_runtime/private/ddc_runtime/errors.dart b/sdk/lib/_internal/js_dev_runtime/private/ddc_runtime/errors.dart index 0a3c9a25350..6b33186ead6 100644 --- a/sdk/lib/_internal/js_dev_runtime/private/ddc_runtime/errors.dart +++ b/sdk/lib/_internal/js_dev_runtime/private/ddc_runtime/errors.dart @@ -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)); } }