[vm] Enable non-nullable experiment in the VM by default

VM was not performing auto-detection of sound null safety mode
if --enable-experiment=non-nullable was not specified on the command
line. This change flips that logic to perform auto-detection unless
--enable-experiment=no-non-nullable is specified.

TEST=Added regression test runtime/tests/vm/dart/regress_44026_test.dart.

Fixes https://github.com/dart-lang/sdk/issues/44026
Fixes https://github.com/dart-lang/sdk/issues/44043

Change-Id: Ide8935e90dd3a8bd5a417aeb758605dedbb853eb
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/170201
Commit-Queue: Alexander Markov <alexmarkov@google.com>
Reviewed-by: Siva Annamalai <asiva@google.com>
This commit is contained in:
Alexander Markov 2020-11-03 22:29:08 +00:00 committed by commit-bot@chromium.org
parent 89de1e82d9
commit 0b3e6bd16c
6 changed files with 74 additions and 3 deletions

View file

@ -0,0 +1,12 @@
// Copyright (c) 2020, the Dart project authors. Please see the AUTHORS file
// for details. All rights reserved. Use of this source code is governed by a
// BSD-style license that can be found in the LICENSE file.
// Main script for regress_44026_test.dart.
// @dart=2.12
import 'regress_44026_opt_out_lib.dart';
void main() {
sayHello(true);
}

View file

@ -0,0 +1,14 @@
// Copyright (c) 2020, the Dart project authors. Please see the AUTHORS file
// for details. All rights reserved. Use of this source code is governed by a
// BSD-style license that can be found in the LICENSE file.
// Opted-out library for regress_44026_test.dart.
// @dart = 2.7
void sayHello(bool t) {
String s;
if (t) {
s = 'hello';
}
print(s);
}

View file

@ -0,0 +1,44 @@
// Copyright (c) 2020, the Dart project authors. Please see the AUTHORS file
// for details. All rights reserved. Use of this source code is governed by a
// BSD-style license that can be found in the LICENSE file.
// OtherResources=regress_44026_main.dart
// OtherResources=regress_44026_opt_out_lib.dart
// Tests that compile-time error is issued if NNBD opted-out library is used
// from opted-in entry point (with null safety auto-detection).
// Regression test for https://github.com/dart-lang/sdk/issues/44026.
import 'dart:io' show File, Platform, Process;
import 'package:expect/expect.dart';
import 'package:path/path.dart' as path;
import 'snapshot_test_helper.dart';
const int kCompilationErrorExitCode = 254;
main() async {
await withTempDir((String temp) async {
// Need to copy test scripts out of Dart SDK to avoid hardcoded
// opted-in/opted-out status for Dart SDK tests.
for (String script in [
'regress_44026_main.dart',
'regress_44026_opt_out_lib.dart'
]) {
final scriptInTemp = path.join(temp, script);
File.fromUri(Platform.script.resolve(script)).copySync(scriptInTemp);
}
// Do not add Platform.executableArguments into arguments to avoid passing
// --sound-null-safety / --no-sound-null-safety arguments.
final result = await Process.run(Platform.executable, [
path.join(temp, 'regress_44026_main.dart'),
]);
print('stdout: ${result.stdout}');
print('stderr: ${result.stderr}');
Expect.equals(kCompilationErrorExitCode, result.exitCode);
Expect.stringContainsInOrder(result.stderr, [
"Error: A library can't opt out of null safety by default, when using sound null safety."
]);
});
}

View file

@ -256,6 +256,7 @@ dart/appjit*: SkipByDesign # Test needs to run from source
dart/kernel_determinism_test: SkipByDesign # Test needs to run from source
dart/minimal_kernel_test: SkipByDesign # Test needs to run from source
dart/null_safety_autodetection_in_kernel_compiler_test: SkipByDesign # Test needs to run from source
dart/regress_44026_test: SkipByDesign # Test needs to run from source
dart/snapshot_depfile_test: SkipByDesign # Test needs to run from source
dart/type_casts_with_null_safety_autodetection_test: SkipByDesign # Test needs to run from source
dart_2/appjit*: SkipByDesign # Test needs to run from source

View file

@ -806,7 +806,7 @@ bool Dart::DetectNullSafety(const char* script_uri,
}
// If we are loading from source, figure out the mode from the source.
if (KernelIsolate::GetExperimentalFlag("non-nullable")) {
if (!KernelIsolate::GetExperimentalFlag("no-non-nullable")) {
return KernelIsolate::DetectNullSafety(script_uri, package_config,
original_working_directory);
}

View file

@ -21,8 +21,8 @@ void main() {
try {
// Running from Source.
testNullSafetyMode(sourcePath, 'Strong Mode');
// Without the enable experiment option it will be in weak mode.
testNullSafetyMode1(sourcePath, 'Weak Mode');
// Without the enable experiment option it will be in strong mode.
testNullSafetyMode1(sourcePath, 'Strong Mode');
// Running from Kernel File.
testNullSafetyMode(dillPath, 'Strong Mode');