mirror of
https://github.com/dart-lang/sdk
synced 2024-09-06 00:59:09 +00:00
[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:
parent
89de1e82d9
commit
0b3e6bd16c
12
runtime/tests/vm/dart/regress_44026_main.dart
Normal file
12
runtime/tests/vm/dart/regress_44026_main.dart
Normal 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);
|
||||
}
|
14
runtime/tests/vm/dart/regress_44026_opt_out_lib.dart
Normal file
14
runtime/tests/vm/dart/regress_44026_opt_out_lib.dart
Normal 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);
|
||||
}
|
44
runtime/tests/vm/dart/regress_44026_test.dart
Normal file
44
runtime/tests/vm/dart/regress_44026_test.dart
Normal 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."
|
||||
]);
|
||||
});
|
||||
}
|
|
@ -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
|
||||
|
|
|
@ -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);
|
||||
}
|
||||
|
|
|
@ -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');
|
||||
|
|
Loading…
Reference in a new issue