diff --git a/pkg/dev_compiler/tool/ddb b/pkg/dev_compiler/tool/ddb index 4c95bf42acf..f52cc0368d5 100755 --- a/pkg/dev_compiler/tool/ddb +++ b/pkg/dev_compiler/tool/ddb @@ -14,8 +14,7 @@ import 'dart:io'; import 'package:args/args.dart' show ArgParser; -import 'package:dev_compiler/src/compiler/js_names.dart' - as js_names; +import 'package:dev_compiler/src/compiler/js_names.dart' as js_names; import 'package:path/path.dart' as p; enum NullSafety { strict, weak, disabled } @@ -50,7 +49,8 @@ void main(List args) async { ..addFlag('sound-null-safety', help: 'Compile for sound null safety at runtime. Passed through to the ' 'DDC binary. Defaults to false.', - negatable: true, defaultsTo: true) + negatable: true, + defaultsTo: true) ..addFlag('emit-debug-symbols', help: 'Pass through flag for DDC, emits debug symbols file along with ' 'the compiled module.', @@ -62,7 +62,6 @@ void main(List args) async { ..addFlag('native-null-assertions', help: 'Run with assertions on non-nullable values returned from native ' 'APIs.', - defaultsTo: true, negatable: true) ..addFlag('weak-null-safety-errors', help: 'Treat weak null safety warnings as errors.', defaultsTo: false) @@ -126,7 +125,9 @@ void main(List args) async { var soundNullSafety = options['sound-null-safety'] as bool; var emitDebugSymbols = options['emit-debug-symbols'] as bool; var nonNullAsserts = options['null-assertions'] as bool; - var nativeNonNullAsserts = options['native-null-assertions'] as bool; + var nativeNonNullAsserts = options.wasParsed('native-null-assertions') + ? options['native-null-assertions'] as bool + : soundNullSafety; var weakNullSafetyErrors = options['weak-null-safety-errors'] as bool; var canaryFeatures = options['canary'] as bool; var entry = p.canonicalize(options.rest.first); diff --git a/sdk/lib/_internal/js_dev_runtime/private/ddc_runtime/types.dart b/sdk/lib/_internal/js_dev_runtime/private/ddc_runtime/types.dart index bf903553ef9..d01fe03a8ed 100644 --- a/sdk/lib/_internal/js_dev_runtime/private/ddc_runtime/types.dart +++ b/sdk/lib/_internal/js_dev_runtime/private/ddc_runtime/types.dart @@ -78,14 +78,20 @@ void nonNullAsserts(bool enable) { } @notNull -bool _nativeNonNullAsserts = false; +bool _nativeNonNullAsserts = compileTimeFlag('soundNullSafety'); -/// Enables null assertions on native APIs to make sure value returned from the -/// browser is sound. +/// Enables null assertions on native APIs to make sure values returned from the +/// browser are sound. /// /// These apply to dart:html and similar web libraries. Note that these only are /// added in sound null-safety only. void nativeNonNullAsserts(bool enable) { + if (enable && !compileTimeFlag('soundNullSafety')) { + _warn('Enabling `native-null-assertions` is only supported when sound null ' + 'safety is enabled.'); + } + // This value is only read from `checkNativeNonNull` and calls to that method + // are only generated in sound null safe code. _nativeNonNullAsserts = enable; }