[vm/nnbd] Test for type casts with null-safety auto-detection
Issue: https://github.com/dart-lang/sdk/issues/41206 Change-Id: Ia07f5aeb518991016bc5f5a1df670bfa9617b0ab Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/144495 Reviewed-by: Régis Crelier <regis@google.com> Reviewed-by: Siva Annamalai <asiva@google.com> Commit-Queue: Alexander Markov <alexmarkov@google.com>
This commit is contained in:
committed by
commit-bot@chromium.org
parent
59b2bc0cdd
commit
1003d3fc36
@@ -0,0 +1,29 @@
|
||||
// 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.
|
||||
|
||||
// Test script for type_casts_with_null_safety_autodetection_test.dart which
|
||||
// is supposed to run in strong mode because it is opted-in.
|
||||
|
||||
import 'package:expect/expect.dart';
|
||||
|
||||
dynamic nullObj;
|
||||
|
||||
@pragma('vm:never-inline')
|
||||
typeCast<T>(x) => x as T;
|
||||
|
||||
doTests() {
|
||||
typeCast<dynamic>(nullObj);
|
||||
typeCast<void>(nullObj);
|
||||
Expect.throwsTypeError(() => typeCast<Object>(nullObj));
|
||||
Expect.throwsTypeError(() => typeCast<int>(nullObj));
|
||||
typeCast<List<int>>(<int>[]);
|
||||
Expect.throwsTypeError(() => typeCast<List<int>>(<Null>[]));
|
||||
}
|
||||
|
||||
main() {
|
||||
for (int i = 0; i < 20; ++i) {
|
||||
doTests();
|
||||
}
|
||||
print('OK(strong)');
|
||||
}
|
||||
@@ -0,0 +1,43 @@
|
||||
// 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=type_casts_with_null_safety_autodetection_strong_script.dart
|
||||
// OtherResources=type_casts_with_null_safety_autodetection_weak_script.dart
|
||||
|
||||
// This test verifies that casts with type testing stubs work as expected
|
||||
// if null safety mode (weak/strong) is auto-detected.
|
||||
|
||||
import 'dart:io' show File, Platform;
|
||||
|
||||
import 'package:path/path.dart' as path;
|
||||
import 'snapshot_test_helper.dart';
|
||||
|
||||
runTest(String script, String output, String temp) async {
|
||||
// Need to copy test scripts out of Dart SDK to avoid hardcoded
|
||||
// opted-in/opted-out status for Dart SDK tests.
|
||||
final scriptInTemp = path.join(temp, script);
|
||||
File.fromUri(Platform.script.resolve(script)).copySync(scriptInTemp);
|
||||
|
||||
// Do not add Platform.executableArguments into arguments to avoid passing
|
||||
// --null-safety / --no-null-safety arguments.
|
||||
final result = await runBinary("RUN $script", Platform.executable, [
|
||||
'--enable-experiment=non-nullable',
|
||||
'--deterministic',
|
||||
'--optimization-counter-threshold=10',
|
||||
'--packages=${Platform.packageConfig}',
|
||||
scriptInTemp,
|
||||
]);
|
||||
expectOutput(output, result);
|
||||
}
|
||||
|
||||
main() async {
|
||||
await withTempDir((String temp) async {
|
||||
await runTest(
|
||||
'type_casts_with_null_safety_autodetection_strong_script.dart',
|
||||
'OK(strong)',
|
||||
temp);
|
||||
await runTest('type_casts_with_null_safety_autodetection_weak_script.dart',
|
||||
'OK(weak)', temp);
|
||||
});
|
||||
}
|
||||
@@ -0,0 +1,31 @@
|
||||
// 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.
|
||||
|
||||
// Test script for type_casts_with_null_safety_autodetection_test.dart which
|
||||
// is supposed to run in weak mode because it is opted-out.
|
||||
|
||||
// @dart=2.6
|
||||
|
||||
import 'package:expect/expect.dart';
|
||||
|
||||
dynamic nullObj;
|
||||
|
||||
@pragma('vm:never-inline')
|
||||
typeCast<T>(x) => x as T;
|
||||
|
||||
void doTests() {
|
||||
typeCast<dynamic>(nullObj);
|
||||
typeCast<void>(nullObj);
|
||||
typeCast<Object>(nullObj);
|
||||
typeCast<int>(nullObj);
|
||||
typeCast<List<int>>(<int>[]);
|
||||
typeCast<List<int>>(<Null>[]);
|
||||
}
|
||||
|
||||
main() {
|
||||
for (int i = 0; i < 20; ++i) {
|
||||
doTests();
|
||||
}
|
||||
print('OK(weak)');
|
||||
}
|
||||
@@ -248,6 +248,7 @@ dart/minimal_kernel_bytecode_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/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
|
||||
dart_2/bytecode_and_ast_mix_test: SkipByDesign # Test needs to run from source
|
||||
dart_2/kernel_determinism_test: SkipByDesign # Test needs to run from source
|
||||
|
||||
@@ -188,6 +188,7 @@ ObjectPtr DartEntry::InvokeCode(const Code& code,
|
||||
Thread* thread) {
|
||||
ASSERT(!code.IsNull());
|
||||
ASSERT(thread->no_callback_scope_depth() == 0);
|
||||
ASSERT(!Isolate::Current()->null_safety_not_set());
|
||||
|
||||
invokestub entrypoint =
|
||||
reinterpret_cast<invokestub>(StubCode::InvokeDartCode().EntryPoint());
|
||||
|
||||
Reference in New Issue
Block a user