[test_runner] Remove nnbd mode options.

In particular, this means the VM tests stop getting invoked with the now-invalid --sound-null-safety flag.

Change-Id: Ia8f5a59e0bf1fd7094508fdc4bb146ebf3034148
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/431360
Reviewed-by: Bob Nystrom <rnystrom@google.com>
Reviewed-by: Kallen Tu <kallentu@google.com>
Commit-Queue: Ryan Macnak <rmacnak@google.com>
This commit is contained in:
Ryan Macnak
2025-06-02 10:59:31 -07:00
committed by Commit Queue
parent 8711f552fd
commit 56636971dc
84 changed files with 13 additions and 1796 deletions
@@ -34,19 +34,6 @@ List<String> _experimentsArgument(
return ['--enable-experiment=${experiments.join(',')}'];
}
List<String> _nnbdModeArgument(TestConfiguration configuration) {
switch (configuration.nnbdMode) {
case NnbdMode.legacy:
return [];
case NnbdMode.strong:
return ['--sound-null-safety'];
case NnbdMode.weak:
return ['--no-sound-null-safety'];
}
throw 'unreachable';
}
/// Grouping of a command with its expected result.
class CommandArtifact {
final List<Command> commands;
@@ -193,7 +180,6 @@ class NoneCompilerConfiguration extends CompilerConfiguration {
else if (_configuration.hotReloadRollback)
'--hot-reload-rollback-test-mode',
...vmOptions,
..._nnbdModeArgument(_configuration),
...testFile.sharedOptions,
..._configuration.sharedOptions,
..._experimentsArgument(_configuration, testFile),
@@ -249,7 +235,6 @@ class VMKernelCompilerConfiguration extends CompilerConfiguration
..._configuration.sharedOptions,
..._experimentsArgument(_configuration, testFile),
...vmOptions,
..._nnbdModeArgument(_configuration),
...args
];
}
@@ -275,7 +260,6 @@ class VMKernelCompilerConfiguration extends CompilerConfiguration
else if (_configuration.hotReloadRollback)
'--hot-reload-rollback-test-mode',
...vmOptions,
..._nnbdModeArgument(_configuration),
...testFile.sharedOptions,
..._configuration.sharedOptions,
..._experimentsArgument(_configuration, testFile),
@@ -985,7 +969,6 @@ class PrecompilerCompilerConfiguration extends CompilerConfiguration
'--no-sim-use-hardfp',
],
if (_configuration.isMinified) '--obfuscate',
..._nnbdModeArgument(_configuration),
if (arguments.contains('--print-flow-graph-optimized'))
'--redirect-isolate-log-to=$tempDir/out.il',
if (arguments.contains('--print-flow-graph-optimized') &&
@@ -1192,7 +1175,6 @@ class PrecompilerCompilerConfiguration extends CompilerConfiguration
return [
if (_enableAsserts) '--enable_asserts',
...vmOptions,
..._nnbdModeArgument(_configuration),
...testFile.sharedOptions,
..._configuration.sharedOptions,
..._experimentsArgument(_configuration, testFile),
@@ -1254,7 +1236,6 @@ class AppJitCompilerConfiguration extends CompilerConfiguration {
return [
if (_enableAsserts) '--enable_asserts',
...vmOptions,
..._nnbdModeArgument(_configuration),
...testFile.sharedOptions,
..._configuration.sharedOptions,
..._experimentsArgument(_configuration, testFile),
@@ -1273,7 +1254,6 @@ class AppJitCompilerConfiguration extends CompilerConfiguration {
return [
if (_enableAsserts) '--enable_asserts',
...vmOptions,
..._nnbdModeArgument(_configuration),
...testFile.sharedOptions,
..._configuration.sharedOptions,
..._experimentsArgument(_configuration, testFile),
@@ -1427,7 +1407,6 @@ abstract mixin class VMKernelCompilerMixin {
arguments.contains('--enable-asserts') ||
arguments.contains('--enable_asserts'))
'--enable-asserts',
..._nnbdModeArgument(_configuration),
..._configuration.genKernelOptions,
];
+2 -11
View File
@@ -109,7 +109,6 @@ class TestConfiguration {
Mode get mode => configuration.mode;
Runtime get runtime => configuration.runtime;
System get system => configuration.system;
NnbdMode get nnbdMode => configuration.nnbdMode;
Sanitizer get sanitizer => configuration.sanitizer;
// Boolean getters
@@ -408,23 +407,15 @@ class TestConfiguration {
/// The set of [Feature]s supported by this configuration.
Set<Feature> get supportedFeatures {
// The analyzer should parse all tests that don't require legacy support.
// The analyzer should handle all tests.
if (compiler == Compiler.dart2analyzer) {
return {...Feature.all.where((f) => !Feature.legacy.contains(f))};
return {...Feature.all};
}
var isDart2jsProduction = dart2jsOptions.contains('-O3');
var isOptimizedDart2Wasm = dart2wasmOptions.contains('-O1');
var isJsCompiler = compiler == Compiler.dart2js || compiler == Compiler.ddc;
return {
// The supported NNBD features depending on the `nnbdMode`.
if (NnbdMode.legacy == configuration.nnbdMode)
Feature.nnbdLegacy
else
Feature.nnbd,
if (NnbdMode.weak == configuration.nnbdMode) Feature.nnbdWeak,
if (NnbdMode.strong == configuration.nnbdMode) Feature.nnbdStrong,
// The configurations with the following builder tags and configurations
// with the `minified` flag set to `true` will obfuscate `Type.toString`
// strings.
-1
View File
@@ -26,7 +26,6 @@ final _variables = {
"jscl": _Variable.bool((c) => c.runtime.isJSCommandLine),
"minified": _Variable.bool((c) => c.isMinified),
"mode": _Variable((c) => c.mode.name, Mode.names),
"nnbd": _Variable((TestConfiguration c) => c.nnbdMode.name, NnbdMode.names),
"qemu": _Variable.bool((c) => c.useQemu),
"runtime": _Variable(_runtimeName, _runtimeNames),
"sanitizer": _Variable((c) => c.sanitizer.name, Sanitizer.names),
-22
View File
@@ -36,21 +36,6 @@ class Feature {
/// Supports native number semantics.
static const nativeNumbers = Feature._("native-numbers");
/// Opted out of NNBD and still using the legacy semantics.
static const nnbdLegacy = Feature._("nnbd-legacy");
/// Opted in to NNBD features.
///
/// Note that this does not imply either strong or weak checking. A test that
/// only requires "nnbd" should run in both weak and strong checking modes.
static const nnbd = Feature._("nnbd");
/// Weak checking of NNBD features.
static const nnbdWeak = Feature._("nnbd-weak");
/// Full strong checking of NNBD features.
static const nnbdStrong = Feature._("nnbd-strong");
/// Expects [Type.toString] to show the original type name and original
/// names in function type named parameters.
static const readableTypeStrings = Feature._("readable-type-strings");
@@ -61,16 +46,9 @@ class Feature {
checkedParameters,
jsNumbers,
nativeNumbers,
nnbdLegacy,
nnbd,
nnbdWeak,
nnbdStrong,
readableTypeStrings,
];
/// All modes that should be tested on a platform that support legacy code.
static const legacy = [nnbdLegacy, nnbdWeak];
final String name;
const Feature._(this.name);
+3 -17
View File
@@ -250,10 +250,6 @@ test options, specifying how tests should be run.''')
hide: true, help: 'Path to safari browser executable.')
..addFlag('use-sdk',
aliases: ['use_sdk'], help: 'Use compiler or runtime from the SDK.')
..addOption('nnbd',
allowed: NnbdMode.names,
defaultsTo: NnbdMode.strong.name,
help: 'Which set of non-nullable type features to use.')
..addOption('output-directory',
aliases: ['output_directory'],
defaultsTo: "logs",
@@ -408,7 +404,6 @@ has been specified on the command line.''')
'compiler',
'runtime',
'timeout',
'nnbd',
'sanitizer',
'enable-asserts',
'use-cfe',
@@ -628,14 +623,13 @@ has been specified on the command line.''')
}
var progress = Progress.find(data["progress"] as String);
var nnbdMode = NnbdMode.find(data["nnbd"] as String);
void addConfiguration(Configuration innerConfiguration,
[String? namedConfiguration]) {
var configuration = TestConfiguration(
configuration: innerConfiguration,
progress: progress,
selectors: _expandSelectors(data, innerConfiguration.nnbdMode),
selectors: _expandSelectors(data),
build: data["build"] as bool,
testList: data["test-list-contents"] as List<String>?,
repeat: int.parse(data["repeat"] as String),
@@ -784,7 +778,6 @@ has been specified on the command line.''')
mode,
runtime,
system,
nnbdMode: nnbdMode,
sanitizer: sanitizer,
timeout: timeout,
enableAsserts: data['enable-asserts'] as bool,
@@ -819,7 +812,7 @@ has been specified on the command line.''')
///
/// If no selectors are explicitly given, uses the default suite patterns.
Map<String, RegExp> _expandSelectors(
Map<String, dynamic> configuration, NnbdMode nnbdMode) {
Map<String, dynamic> configuration) {
var selectors = configuration['selectors'] as List<String>? ?? [];
if (selectors.isEmpty || configuration['default-suites'] as bool) {
@@ -904,7 +897,7 @@ class OptionParseException implements Exception {
/// given filter options.
///
/// If any of the options `--system`, `--arch`, `--mode`, `--compiler`,
/// `--nnbd`, or `--runtime` (or their abbreviations) are passed, then only
/// or `--runtime` (or their abbreviations) are passed, then only
/// configurations matching those are shown.
void findConfigurations(Map<String, dynamic> options) {
var testMatrix = TestMatrix.fromPath('tools/bots/test_matrix.json');
@@ -935,11 +928,6 @@ void findConfigurations(Map<String, dynamic> options) {
var compilers = [...(options['compiler'] as List<String>).map(Compiler.find)];
var runtimes = [...(options['runtime'] as List<String>).map(Runtime.find)];
NnbdMode? nnbdMode;
if (options.containsKey('nnbd')) {
nnbdMode = NnbdMode.find(options['nnbd'] as String);
}
var names = SplayTreeSet<String>();
for (var configuration in testMatrix.configurations) {
if (system != null && configuration.system != system) continue;
@@ -954,7 +942,6 @@ void findConfigurations(Map<String, dynamic> options) {
if (runtimes.isNotEmpty && !runtimes.contains(configuration.runtime)) {
continue;
}
if (nnbdMode != null && configuration.nnbdMode != nnbdMode) continue;
names.add(configuration.name);
}
@@ -965,7 +952,6 @@ void findConfigurations(Map<String, dynamic> options) {
if (modes.isNotEmpty) "mode=$modes",
if (compilers.isNotEmpty) "compiler=$compilers",
if (runtimes.isNotEmpty) "runtime=$runtimes",
if (nnbdMode != null) "nnbd=$nnbdMode",
];
if (filters.isEmpty) {
-1
View File
@@ -349,7 +349,6 @@ class VMTestSuite extends TestSuite {
if (expectations.contains(Expectation.crash)) '--suppress-core-dump',
if (experiments.isNotEmpty)
'--enable-experiment=${experiments.join(",")}',
if (configuration.nnbdMode == NnbdMode.strong) '--sound-null-safety',
...configuration.standardOptions,
...configuration.vmOptions,
test.name
+6 -19
View File
@@ -18,7 +18,7 @@ void main() {
void testDefaults() {
// TODO(rnystrom): Test other options.
var configuration = parseConfiguration([]);
Expect.equals(NnbdMode.strong, configuration.nnbdMode);
Expect.equals(Progress.line, configuration.progress);
}
void testOptions() {
@@ -28,15 +28,12 @@ void testOptions() {
Expect.equals(Mode.debug, configurations[0].mode);
Expect.equals(Mode.release, configurations[1].mode);
var configuration = parseConfiguration(['--nnbd=weak']);
Expect.equals(NnbdMode.weak, configuration.nnbdMode);
// Filter invalid configurations when not passing a named configuration.
configurations = parseConfigurations(['--arch=simarm', '--system=android']);
Expect.isEmpty(configurations);
// Special handling for *-options.
configuration = parseConfiguration([
var configuration = parseConfiguration([
'--dart2js-options=a b c',
'--vm-options=d e f',
'--shared-options=g h i'
@@ -90,25 +87,15 @@ void testValidation() {
expectValidationError(['--progress=compact,silent'],
'"compact,silent" is not an allowed value for option "--progress".');
expectValidationError(['--nnbd=unknown'],
'"unknown" is not an allowed value for option "--nnbd".');
// Don't allow multiple.
expectValidationError(['--nnbd=weak,strong'],
'"weak,strong" is not an allowed value for option "--nnbd".');
// Don't allow invalid named configurations.
expectValidationError(['-ninvalid-vm-android-simarm'],
'The named configuration "invalid-vm-android-simarm" is invalid.');
}
void testSelectors() {
// Default null safe suites.
for (var arguments in [
<String>[],
['--nnbd=strong'],
['-nvm-strong']
]) {
var configuration = parseConfiguration(arguments);
// Default suites.
{
final configuration = parseConfiguration([]);
Expect.setEquals({
'samples',
'standalone',
@@ -119,7 +106,7 @@ void testSelectors() {
'lib',
'kernel',
'ffi',
}, configuration.selectors.keys, "suites for $arguments");
}, configuration.selectors.keys, "default suites");
}
// The test runner can run individual tests by being given the
-7
View File
@@ -7,7 +7,6 @@
import 'dart:io';
import 'package:expect/expect.dart';
import 'package:test_runner/src/feature.dart';
import 'package:test_runner/src/path.dart';
import 'package:test_runner/src/static_error.dart';
import 'package:test_runner/src/test_file.dart';
@@ -112,7 +111,6 @@ void testParseOtherOptions() {
/\/ ddcOptions=ddc options
/\/ OtherResources=other resources
/\/ SharedObjects=shared objects
/\/ Requirements=nnbd nnbd-strong
""");
Expect.listEquals(["dart", "options"], file.dartOptions);
Expect.listEquals(["shared", "options"], file.sharedOptions);
@@ -120,7 +118,6 @@ void testParseOtherOptions() {
Expect.listEquals(["dart2wasm", "options"], file.dart2wasmOptions);
Expect.listEquals(["ddc", "options"], file.ddcOptions);
Expect.listEquals(["other", "resources"], file.otherResources);
Expect.listEquals([Feature.nnbd, Feature.nnbdStrong], file.requirements);
// Disallows multiple lines for some options.
expectParseThrows("""
@@ -143,10 +140,6 @@ void testParseOtherOptions() {
/\/ ddcOptions=first
/\/ ddcOptions=second
""");
expectParseThrows("""
/\/ Requirements=nnbd
/\/ Requirements=nnbd-strong
""");
// Merges multiple lines for others.
file = createTestFile(source: """
+2 -4
View File
@@ -7,8 +7,6 @@
"options": {
"compiler": "dartkp"
}
},
"vm-legacy": {},
"vm-strong": {}
}
}
}
}
-28
View File
@@ -10,37 +10,9 @@ import 'package:test_runner/src/test_file.dart';
import 'utils.dart';
void main() {
testNnbdRequirements();
testVmOptions();
}
void testNnbdRequirements() {
// Note: The backslashes are to avoid the test_runner thinking these are
// Requirements markers for this file itself.
var testFiles = [
createTestFile(source: "", path: "none_test.dart"),
createTestFile(source: "/\/ Requirements=nnbd", path: "nnbd_test.dart"),
createTestFile(
source: "/\/ Requirements=nnbd-legacy", path: "legacy_test.dart"),
createTestFile(
source: "/\/ Requirements=nnbd-weak", path: "weak_test.dart"),
createTestFile(
source: "/\/ Requirements=nnbd-strong", path: "strong_test.dart"),
];
expectTestCases([], testFiles,
["language/none_test", "language/nnbd_test", "language/strong_test"]);
expectTestCases(["--nnbd=legacy"], testFiles,
["language/none_test", "language/legacy_test"]);
expectTestCases(["--nnbd=weak"], testFiles,
["language/none_test", "language/nnbd_test", "language/weak_test"]);
expectTestCases(["--nnbd=strong"], testFiles,
["language/none_test", "language/nnbd_test", "language/strong_test"]);
}
void testVmOptions() {
// Note: The backslashes are to avoid the test_runner thinking these are
// Requirements markers for this file itself.
@@ -1,19 +0,0 @@
// Copyright (c) 2018, 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 checking that null is handled correctly at the call-sites that
// are tracking static type exactness.
// Requirements=nnbd-weak
import 'package:expect/expect.dart';
void invokeAdd(List<int> l) {
l.add(10);
}
void main() {
dynamic myNull;
Expect.throws(() => invokeAdd(myNull), (error) => error is NoSuchMethodError);
}
@@ -1,28 +0,0 @@
// 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.
// Verifies that mixin deduplication correctly handles identical anonymous
// mixins from opt-in and opt-out libraries.
// Regression test for https://github.com/dart-lang/sdk/issues/42656.
// Requirements=nnbd-weak
import 'package:expect/expect.dart';
import 'regress_42656_opt_in_lib.dart';
import 'regress_42656_opt_out_lib.dart';
void main() {
Expect.equals('MixinA', C2().toString());
Expect.equals('MixinB', D2().toString());
Expect.equals('MixinA', E2().toString());
Expect.equals('MixinB', F2().toString());
Expect.isFalse(C2() == C2());
Expect.isFalse(D2() == D2());
Expect.isFalse(E2() == E2());
Expect.isFalse(F2() == F2());
Expect.equals(42, C2().x);
Expect.equals(3, D2().y);
Expect.equals(42, E2().x);
Expect.equals(3, F2().y);
}
-4
View File
@@ -29,7 +29,6 @@ dart/gen_snapshot_include_resolved_urls_test: Pass, Slow # Spawns several subpro
dart/hash_map_probes_limit_test: Pass, Slow # Test includes large program compilation.
dart/incompatible_loading_unit_test: Pass, Slow # Spawns several subprocesses
dart/isolates/*: Pass, Slow # Tests use many isolates and take a longer time.
dart/isolates/concurrency_stress_sanity_test: Pass, Slow # Spawns subprocesses
dart/isolates/fast_object_copy_test: Pass, Slow # Slow due to doing a lot of transitive object copies.
dart/minimal_kernel_test: Pass, Slow # Spawns several subprocesses
dart/print_object_layout_test: Pass, Slow # Spawns several subprocesses
@@ -114,9 +113,6 @@ cc/CreateMirrorSystem: SkipByDesign # Imports dart:mirrors
cc/StandaloneSnapshotSize: SkipByDesign # Imports dart:mirrors
dart/gen_snapshot_include_resolved_urls_test: SkipByDesign # Script URLs not included in product gen_snapshot
[ $nnbd == legacy ]
dart/*: SkipByDesign # Migrated tests are not supposed to run on non-NNBD bots.
[ $sanitizer == asan ]
dart/transferable_throws_oom_test: SkipByDesign # This test tries to allocate too much memory on purpose. Still dartbug.com/37188
-2
View File
@@ -2,8 +2,6 @@
// 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.
// Requirements=nnbd-strong
import "dart:collection";
import "package:expect/expect.dart";
import 'cast_helper.dart';
-99
View File
@@ -1,99 +0,0 @@
// 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.
// Requirements=nnbd-weak
import "dart:collection";
import "package:expect/expect.dart";
import 'cast_helper.dart';
void main() {
testIterable();
testList();
testMap();
testSet();
}
testIterable() {
var iterable = new Iterable<C?>.generate(elements.length, (n) => elements[n]);
// Downcast non-nullable.
// An iterable that (likely) can do direct access.
var dIterableDirect = Iterable.castFrom<C?, D>(iterable);
Expect.equals(d, dIterableDirect.elementAt(1));
Expect.equals(null, dIterableDirect.skip(3).elementAt(1));
// An iterable that cannot do direct access.
var dIterableNonDirect = Iterable.castFrom<C?, D>(
iterable.where((_) => true),
);
Expect.equals(d, dIterableNonDirect.elementAt(1));
Expect.equals(null, dIterableNonDirect.skip(3).elementAt(1));
// Iterable that definitely won't survive accessing element 3.
var iterableLimited = new Iterable<C?>.generate(
elements.length,
(n) => n == 3 ? throw "untouchable" : elements[n],
);
var dIterableLimited = Iterable.castFrom<C?, D>(iterableLimited);
Expect.equals(d, dIterableLimited.elementAt(1));
Expect.equals(null, dIterableLimited.skip(3).elementAt(1));
// Upcast non-nullable.
var objectIterable = Iterable.castFrom<C?, Object>(iterable);
Expect.equals(null, objectIterable.skip(3).elementAt(1));
}
testList() {
var list = new List<C?>.from(elements);
// Downcast non-nullable.
var dList = List.castFrom<C?, D>(list);
Expect.equals(d, dList[1]);
Expect.equals(null, dList.last);
// Upcast non-nullable.
var objectList = List.castFrom<C?, Object>(list);
Expect.equals(null, objectList.last);
}
testMap() {
var map = new Map.fromIterables(elements, elements);
// Downcast non-nullable.
var dMap = Map.castFrom<C?, C?, D, D>(map);
Expect.equals(d, dMap[d]);
Expect.isTrue(dMap.containsKey(null));
Expect.equals(null, dMap[null]);
// Test keys and values
Expect.isTrue(dMap.keys is Iterable<D>);
Expect.isTrue(dMap.values is Iterable<D>);
Expect.throws(() => dMap.keys.toList());
Expect.throws(() => dMap.values.toList());
// Upcast non-nullable.
var objectMap = Map.castFrom<C?, C?, Object, Object>(map);
Expect.isTrue(objectMap.containsKey(null));
Expect.equals(null, objectMap[null]);
// Test keys and values
Expect.isTrue(objectMap.keys is Iterable<Object>);
Expect.isTrue(objectMap.values is Iterable<Object>);
var expectedValues = new List<Object>.from(elements);
Expect.listEquals(expectedValues, objectMap.values.toList());
}
testSet() {
var setEls = new Set<C?>.from(elements);
// Downcast non-nullable.
var dSet = Set.castFrom<C?, D>(setEls);
Expect.equals(d, dSet.elementAt(1));
Expect.equals(null, dSet.last);
// Upcast non-nullable.
var objectSet = Set.castFrom<C?, Object>(setEls);
Expect.equals(null, objectSet.last);
}
-1
View File
@@ -3,7 +3,6 @@
// BSD-style license that can be found in the LICENSE file.
// Regression test for https://github.com/dart-lang/sdk/issues/42502.
// Requirements=nnbd-strong
import "package:expect/expect.dart";
@@ -2,8 +2,6 @@
// 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.
// Requirements=nnbd
import 'package:expect/expect.dart';
void main() {
@@ -4,8 +4,6 @@
// Tests that JS interop works with hot restart.
// Requirements=nnbd
@JS()
library hot_restart_js_interop_test;
-2
View File
@@ -2,8 +2,6 @@
// 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.
// Requirements=nnbd
@JS()
library js_interop_test;
-2
View File
@@ -2,8 +2,6 @@
// 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.
// Requirements=nnbd-strong
import 'dart:_foreign_helper' show TYPE_REF;
import 'dart:async' show FutureOr;
-277
View File
@@ -1,277 +0,0 @@
// 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.
// Requirements=nnbd-weak
import 'dart:_foreign_helper' show TYPE_REF;
import 'dart:async';
import 'runtime_utils.dart'
show
checkSubtype,
checkProperSubtype,
checkMutualSubtype,
checkSubtypeFailure;
class A {}
class B extends A {}
class C extends B {}
class D<T extends B> {}
class E<T, S> {}
class F extends E<B, B> {}
void main() {
// Top type symmetry.
// Object? <:> dynamic
checkMutualSubtype(TYPE_REF<Object?>(), TYPE_REF<dynamic>());
// Object? <:> void
checkMutualSubtype(TYPE_REF<Object?>(), TYPE_REF<void>());
// void <:> dynamic
checkMutualSubtype(TYPE_REF<void>(), TYPE_REF<dynamic>());
// Bottom is subtype of top.
// Never <: dynamic
checkProperSubtype(TYPE_REF<Never>(), TYPE_REF<dynamic>());
// Never <: void
checkProperSubtype(TYPE_REF<Never>(), TYPE_REF<void>());
// Never <: Object?
checkProperSubtype(TYPE_REF<Never>(), TYPE_REF<Object?>());
// Object is between top and bottom.
// Object <: Object?
checkSubtype(TYPE_REF<Object>(), TYPE_REF<Object?>());
// Never <: Object
checkProperSubtype(TYPE_REF<Never>(), TYPE_REF<Object>());
// Null is between top and bottom.
// Null <: Object?
checkProperSubtype(TYPE_REF<Null>(), TYPE_REF<Object?>());
// Never <: Null
checkSubtype(TYPE_REF<Never>(), TYPE_REF<Null>());
// Class is between Object and bottom.
// A <: Object
checkProperSubtype(TYPE_REF<A>(), TYPE_REF<dynamic>());
// Never <: A
checkProperSubtype(TYPE_REF<Never>(), TYPE_REF<A>());
// Nullable types are a union of T and Null.
// A <: A?
checkSubtype(TYPE_REF<A>(), TYPE_REF<A?>());
// Null <: A?
checkProperSubtype(TYPE_REF<Null>(), TYPE_REF<A?>());
// A? <: Object?
checkProperSubtype(TYPE_REF<A?>(), TYPE_REF<Object?>());
// Futures.
// Null <: FutureOr<Object?>
checkProperSubtype(TYPE_REF<Null>(), TYPE_REF<FutureOr<Object?>>());
// Object <: FutureOr<Object?>
checkSubtype(TYPE_REF<Object>(), TYPE_REF<FutureOr<Object?>>());
// Object? <:> FutureOr<Object?>
checkMutualSubtype(TYPE_REF<Object?>(), TYPE_REF<FutureOr<Object?>>());
// Object <:> FutureOr<Object>
checkMutualSubtype(TYPE_REF<Object>(), TYPE_REF<FutureOr<Object>>());
// Object <:> FutureOr<dynamic>
checkMutualSubtype(TYPE_REF<Object>(), TYPE_REF<FutureOr<dynamic>>());
// Object <:> FutureOr<void>
checkMutualSubtype(TYPE_REF<Object>(), TYPE_REF<FutureOr<void>>());
// Future<Object> <: FutureOr<Object?>
checkProperSubtype(TYPE_REF<Future<Object>>(), TYPE_REF<FutureOr<Object?>>());
// Future<Object?> <: FutureOr<Object?>
checkProperSubtype(
TYPE_REF<Future<Object?>>(),
TYPE_REF<FutureOr<Object?>>(),
);
// FutureOr<Never> <: Future<Never>
checkSubtype(TYPE_REF<FutureOr<Never>>(), TYPE_REF<Future<Never>>());
// Future<B> <: FutureOr<A>
checkProperSubtype(TYPE_REF<Future<B>>(), TYPE_REF<FutureOr<A>>());
// B <: <: FutureOr<A>
checkProperSubtype(TYPE_REF<B>(), TYPE_REF<FutureOr<A>>());
// Future<B> <: Future<A>
checkProperSubtype(TYPE_REF<Future<B>>(), TYPE_REF<Future<A>>());
// Interface subtypes.
// A <: A
checkSubtype(TYPE_REF<A>(), TYPE_REF<A>());
// B <: A
checkProperSubtype(TYPE_REF<B>(), TYPE_REF<A>());
// C <: B
checkProperSubtype(TYPE_REF<C>(), TYPE_REF<B>());
// C <: A
checkProperSubtype(TYPE_REF<C>(), TYPE_REF<A>());
// Functions.
// A -> B <: Function
checkProperSubtype(TYPE_REF<B Function(A)>(), TYPE_REF<Function>());
// A -> B <: A -> B
checkSubtype(TYPE_REF<B Function(A)>(), TYPE_REF<B Function(A)>());
// A -> B <: B -> B
checkProperSubtype(TYPE_REF<B Function(A)>(), TYPE_REF<B Function(B)>());
// A -> B <: A -> A
checkProperSubtype(TYPE_REF<B Function(A)>(), TYPE_REF<A Function(A)>());
// Generic Function Subtypes.
// Bound is a built in type.
// <T extends int> void -> void <: <T extends int> void -> void
checkSubtype(
TYPE_REF<void Function<T extends int>()>(),
TYPE_REF<void Function<T extends int>()>(),
);
// <T extends String> A -> T <: <T extends String> B -> T
checkProperSubtype(
TYPE_REF<T Function<T extends String>(A)>(),
TYPE_REF<T Function<T extends String>(B)>(),
);
// <T extends double> T -> B <: <T extends double> T -> A
checkProperSubtype(
TYPE_REF<B Function<T extends double>(T)>(),
TYPE_REF<A Function<T extends double>(T)>(),
);
// Bound is a function type.
// <T extends A -> B> void -> void <: <T extends A -> B> void -> void
checkSubtype(
TYPE_REF<void Function<T extends B Function(A)>()>(),
TYPE_REF<void Function<T extends B Function(A)>()>(),
);
// <T extends A -> B> A -> T <: <T extends A -> B> B -> T
checkProperSubtype(
TYPE_REF<T Function<T extends B Function(A)>(A)>(),
TYPE_REF<T Function<T extends B Function(A)>(B)>(),
);
// <T extends A -> B> T -> B <: <T extends A -> B> T -> A
checkProperSubtype(
TYPE_REF<B Function<T extends B Function(A)>(T)>(),
TYPE_REF<A Function<T extends B Function(A)>(T)>(),
);
// Bound is a user defined class.
// <T extends B> void -> void <: <T extends B> void -> void
checkSubtype(
TYPE_REF<void Function<T extends B>()>(),
TYPE_REF<void Function<T extends B>()>(),
);
// <T extends B> A -> T <: <T extends B> B -> T
checkProperSubtype(
TYPE_REF<T Function<T extends B>(A)>(),
TYPE_REF<T Function<T extends B>(B)>(),
);
// <T extends B> T -> B <: <T extends B> T -> A
checkProperSubtype(
TYPE_REF<B Function<T extends B>(T)>(),
TYPE_REF<A Function<T extends B>(T)>(),
);
// Bound is a Future.
// <T extends Future<B>> void -> void <: <T extends Future<B>> void -> void
checkSubtype(
TYPE_REF<void Function<T extends Future<B>>()>(),
TYPE_REF<void Function<T extends Future<B>>()>(),
);
// <T extends Future<B>> A -> T <: <T extends Future<B>> B -> T
checkProperSubtype(
TYPE_REF<T Function<T extends Future<B>>(A)>(),
TYPE_REF<T Function<T extends Future<B>>(B)>(),
);
// <T extends Future<B>> T -> B <: <T extends Future<B>> T -> A
checkProperSubtype(
TYPE_REF<B Function<T extends Future<B>>(T)>(),
TYPE_REF<A Function<T extends Future<B>>(T)>(),
);
// Bound is a FutureOr.
// <T extends FutureOr<B>> void -> void <:
// <T extends FutureOr<B>> void -> void
checkSubtype(
TYPE_REF<void Function<T extends FutureOr<B>>()>(),
TYPE_REF<void Function<T extends FutureOr<B>>()>(),
);
// <T extends FutureOr<B>> A -> T <: <T extends FutureOr<B>> B -> T
checkProperSubtype(
TYPE_REF<T Function<T extends Future<B>>(A)>(),
TYPE_REF<T Function<T extends Future<B>>(B)>(),
);
// <T extends FutureOr<B>> T -> B <: <T extends FutureOr<B>> T -> A
checkProperSubtype(
TYPE_REF<B Function<T extends Future<B>>(T)>(),
TYPE_REF<A Function<T extends Future<B>>(T)>(),
);
// Generics.
// D <:> D<B>
checkMutualSubtype(TYPE_REF<D>(), TYPE_REF<D<B>>());
// D<C> <: D<B>
checkProperSubtype(TYPE_REF<D<C>>(), TYPE_REF<D<B>>());
// F <: E
checkProperSubtype(TYPE_REF<F>(), TYPE_REF<E>());
// F <: E<A, A>
checkProperSubtype(TYPE_REF<F>(), TYPE_REF<E<A, A>>());
// E<B, B> <: E
checkProperSubtype(TYPE_REF<E<B, B>>(), TYPE_REF<E>());
// E<B, B> <: E<A, A>
checkProperSubtype(TYPE_REF<E<B, B>>(), TYPE_REF<E<A, A>>());
// Nullable interface subtypes.
// B <: A?
checkProperSubtype(TYPE_REF<B>(), TYPE_REF<A?>());
// C <: A?
checkProperSubtype(TYPE_REF<C>(), TYPE_REF<A?>());
// B? <: A?
checkProperSubtype(TYPE_REF<B?>(), TYPE_REF<A?>());
// C? <: A?
checkProperSubtype(TYPE_REF<C?>(), TYPE_REF<A?>());
// Allowed in weak mode.
// dynamic <: Object
checkSubtype(TYPE_REF<dynamic>(), TYPE_REF<Object>());
// void <: Object
checkSubtype(TYPE_REF<void>(), TYPE_REF<Object>());
// Object? <: Object
checkSubtype(TYPE_REF<Object?>(), TYPE_REF<Object>());
// A? <: Object
checkProperSubtype(TYPE_REF<A?>(), TYPE_REF<Object>());
// A? <: A
checkSubtype(TYPE_REF<A?>(), TYPE_REF<A>());
// Null <: Never
checkSubtype(TYPE_REF<Null>(), TYPE_REF<Never>());
// Null <: Object
checkProperSubtype(TYPE_REF<Null>(), TYPE_REF<Object>());
// Null <: A
checkProperSubtype(TYPE_REF<Null>(), TYPE_REF<A>());
// Null <: FutureOr<A>
checkProperSubtype(TYPE_REF<Null>(), TYPE_REF<FutureOr<A>>());
// Null <: Future<A>
checkProperSubtype(TYPE_REF<Null>(), TYPE_REF<Future<A>>());
// FutureOr<Null> <: Future<Null>
checkSubtype(TYPE_REF<FutureOr<Null>>(), TYPE_REF<Future<Null>>());
// Null <: Future<A?>
checkProperSubtype(TYPE_REF<Null>(), TYPE_REF<Future<A?>>());
// FutureOr<Object?> <: Object
checkSubtype(TYPE_REF<FutureOr<Object?>>(), TYPE_REF<Object>());
// FutureOr<dynamic> <: Object
checkSubtype(TYPE_REF<FutureOr<dynamic>>(), TYPE_REF<Object>());
// FutureOr<void> <: Object
checkSubtype(TYPE_REF<FutureOr<void>>(), TYPE_REF<Object>());
}
@@ -1,45 +0,0 @@
// 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.
// Requirements=nnbd-weak
// ddcOptions=--weak-null-safety-errors
import 'package:expect/expect.dart';
/// Code that runs without error when running with unsound null safety but
/// should throw in sound mode or when running DDC with
/// `--weak-null-safety-errors`.
void fn(StringBuffer arg) {}
void testArg<T>(T t) => throw 'do not call';
T testReturn<T>() => throw 'do not call';
const c = C<Duration>();
class C<T> {
covariantCheck(List<T> t) {}
const C();
}
void main() {
Expect.throwsTypeError(() => null as int);
dynamic dynamicNull = null;
Expect.throwsTypeError(() => fn(dynamicNull));
Expect.throwsTypeError(() => [Duration(days: 1), null] as List<Duration>);
// Constants get legacy types introduced in their type arguments.
C<Duration?> c2 = c;
Expect.throwsTypeError(() => c2.covariantCheck([Duration(days: 1), null]));
// Tearoff instantiations are "potentially constant" and are treated as a
// constant by the CFE.
// When compiling for unsound null safety the resulting type signature
// attached to the tearoff is `void Function(Duration*)` which is a valid
// subtype of `void Function(Duration?)`. In sound null safety the signature
// is `void Function(Duration)` which should fail in the cast.
Expect.throwsTypeError(() => (testArg<Duration>) as void Function(Duration?));
Expect.throwsTypeError(() => (testReturn<Duration?>) as Duration Function());
}
-3
View File
@@ -43,9 +43,6 @@ function_callbacks_structs_by_value_generated_test: Pass, Slow
[ $mode == product ]
regress_47594_test: Skip # Profiler is not available in Product.
[ $nnbd == weak ]
vmspecific_pointer_load_il_test: SkipByDesign # Unsound NNBD boxes things because of nulls.
[ $system == android ]
*: Pass, Slow # https://github.com/dart-lang/sdk/issues/38489
regress_47594_test: Skip # DartDev is not available on Android.
@@ -2,8 +2,6 @@
// 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.
// Requirements=nnbd-strong
import 'dart:async';
import 'package:expect/expect.dart';
import 'package:expect/static_type_helper.dart';
@@ -8,8 +8,6 @@
//
// Regression test for https://github.com/dart-lang/sdk/issues/49396.
// Requirements=nnbd-strong
import 'dart:async';
import 'package:expect/expect.dart';
import 'package:expect/static_type_helper.dart';
@@ -2,8 +2,6 @@
// 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.
// Requirements=nnbd-strong
import "package:expect/expect.dart";
main() {
-17
View File
@@ -1,17 +0,0 @@
// Copyright (c) 2014, 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.
// Requirements=nnbd-weak
import "package:expect/expect.dart";
main() {
Expect.throwsAssertionError(() {
if (null as dynamic) {}
});
Expect.throwsTypeError(() {
if ("true" as dynamic) {}
});
}
@@ -2,8 +2,6 @@
// 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.
// Requirements=nnbd-strong
// Check that passing `null` for a boolean typed parameter will still cause
// a boolean conversion error when used in a condition.
@@ -1,26 +0,0 @@
// Copyright (c) 2015, 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.
// Requirements=nnbd-weak
// Check that passing `null` for a boolean typed parameter will still cause
// a boolean conversion error when used in a condition.
import 'package:expect/expect.dart';
@pragma('dart2js:noInline')
String check({bool? a, bool? b}) {
String aString = (a as dynamic) ? 'a' : '';
String bString = (b as dynamic) ? 'b' : '';
return '$aString$bString';
}
class Class {
final String field;
Class({bool? a = false, bool? b = true}) : this.field = check(a: a, b: b);
}
main() {
Expect.throwsAssertionError(() => new Class(a: null, b: null).field);
}
@@ -2,7 +2,6 @@
// 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.
// Requirements=nnbd-strong
import "package:expect/expect.dart";
main() {
@@ -1,31 +0,0 @@
// Copyright (c) 2017, 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.
// Requirements=nnbd-weak
import "package:expect/expect.dart";
main() {
// Pre-NNBD bottom type.
int Function(Null) f = (x) => 1; // Runtime type is int Function(Object?)
Expect.isTrue(f is int Function(Null));
Expect.isTrue(f is int Function(Never));
Expect.isTrue(f is int Function(String));
Expect.isTrue(f is int Function(Object));
Expect.isTrue(f is int Function(Object?));
// NNBD bottom type.
int Function(Never) g = (x) => 1; // Runtime type is int Function(Object?)
Expect.isTrue(g is int Function(Null));
Expect.isTrue(g is int Function(Never));
Expect.isTrue(g is int Function(String));
Expect.isTrue(g is int Function(Object));
Expect.isTrue(g is int Function(Object?));
int Function(String) h = (x) => 1; // Runtime type is int Function(String)
Expect.isTrue(h is int Function(Null));
Expect.isTrue(h is int Function(Never));
Expect.isTrue(h is int Function(String));
Expect.isFalse(h is int Function(Object));
Expect.isFalse(h is int Function(Object?));
}
@@ -2,8 +2,6 @@
// 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.
// Requirements=nnbd-strong
// Copied from constructor12_test.dart to break out a single expectation that
// is different in weak and strong modes.
@@ -1,18 +0,0 @@
// Copyright (c) 2015, 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.
// Requirements=nnbd-weak
// Copied from constructor12_test.dart to break out a single expectation that
// is different in weak and strong modes.
import "package:expect/expect.dart";
import 'constructor12_lib.dart';
main() {
var a2 = confuse(new A(2));
// Only true in weak mode.
Expect.isTrue(a2 is A<Object>);
}
@@ -2,7 +2,6 @@
// 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.
// Requirements=nnbd-strong
import 'package:expect/expect.dart';
void main() {
@@ -1,23 +0,0 @@
// Copyright (c) 2019, 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.
// Requirements=nnbd-weak
import 'package:expect/expect.dart';
void main() {
// Null condition expression.
dynamic nullBool = null;
Expect.throwsAssertionError(() => <int>[for (; nullBool;) 1]);
Expect.throwsAssertionError(() => <int, int>{for (; nullBool;) 1: 1});
Expect.throwsAssertionError(() => <int>{for (; nullBool;) 1});
// Null iterable.
dynamic nullIterable = null;
// The current behavior is inconsistent across the backends. The VM currently
// tries calling .iterable and throws a NoSuchMethodError. DDC throws a
// TypeError.
Expect.throws(() => <int>[for (var i in nullIterable) 1]);
Expect.throws(() => <int, int>{for (var i in nullIterable) 1: 1});
Expect.throws(() => <int>{for (var i in nullIterable) 1});
}
@@ -2,7 +2,6 @@
// 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.
// Requirements=nnbd-strong
import 'package:expect/expect.dart';
void main() {
@@ -1,13 +0,0 @@
// 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.
// Requirements=nnbd-weak
import 'package:expect/expect.dart';
void main() {
dynamic nullBool;
Expect.throwsAssertionError(() => <int>[if (nullBool) 1]);
Expect.throwsAssertionError(() => <int, int>{if (nullBool) 1: 1});
Expect.throwsAssertionError(() => <int>{if (nullBool) 1});
}
@@ -2,8 +2,6 @@
// 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.
// Requirements=nnbd-strong
import "package:expect/expect.dart";
import 'package:expect/variations.dart' as v;
@@ -1,26 +0,0 @@
// 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.
// Requirements=nnbd-weak
import "package:expect/expect.dart";
typedef dynamicToDynamic = dynamic Function(dynamic);
typedef voidToT = T Function<T>();
dynamic dynamicNull = null;
dynamic cast<T>(dynamic value) => value as T;
bool allowsArgument(T Function<T>() fn) => true;
main() {
// In weak mode Null should be allowed as a subtype of function types.
Expect.equals(null, dynamicNull as Function);
Expect.equals(null, dynamicNull as dynamicToDynamic);
Expect.equals(null, cast<dynamic Function(dynamic)>(dynamicNull));
Expect.equals(null, dynamicNull as voidToT);
Expect.equals(true, allowsArgument(dynamicNull));
}
@@ -2,8 +2,6 @@
// 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.
// Requirements=nnbd-strong
// Test implicit casts and null conversions for boolean expressions
// in strong mode.
@@ -2,8 +2,6 @@
// 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.
// Requirements=nnbd-strong
/// Test instance checks and casts in constants may use potentially constant
/// types, and cause compile time errors when the casts fail.
@@ -2,8 +2,6 @@
// 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.
// Requirements=nnbd-strong
/// Test instance checks and casts in constants may use potentially constant
/// types, and evaluate appropriately.
@@ -2,8 +2,6 @@
// 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.
// Requirements=nnbd-strong
/// Test that `Never` has all members, and that as a result no extensions
/// apply to it. Also test that `Never` is inferred as the type of a
/// throw expression, and as the return type of function literals that
@@ -2,8 +2,6 @@
// 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.
// Requirements=nnbd-strong
import 'package:expect/expect.dart';
import 'never_null_assignability_lib1.dart';
@@ -2,8 +2,6 @@
// 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.
// Requirements=nnbd-strong
import 'package:expect/expect.dart';
// Test that it is an error if a named parameter that is part of a required
@@ -2,7 +2,6 @@
// 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.
// Requirements=nnbd-strong
// Tests runtime type semantics for functions with required named parameters
// in strong mode.
import 'package:expect/expect.dart';
@@ -1,27 +0,0 @@
// 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.
// Requirements=nnbd-weak
// Tests runtime type semantics for functions with required named parameters
// in weak mode.
import 'package:expect/expect.dart';
import 'required_named_args_lib.dart';
main() {
dynamic f = func;
// Valid: Subtype may redeclare optional parameters as required in weak mode.
Function(String p0, {required int p1, String p2}) t2 = f;
// Valid: Subtype may declare new required named parameters in weak mode.
Function(String p0, {required int p1}) t3 = f;
// Valid: Invocation may pass null as a required named argument in weak mode.
f("", p1: null, p2: null);
Function.apply(f, [""], {#p1: null, #p2: null});
// Valid: Invocation may omit a required named argument in weak mode.
f("", p1: 100);
Function.apply(f, [""], {#p1: 100});
}
@@ -2,8 +2,6 @@
// 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.
// Requirements=nnbd-strong
import 'package:expect/expect.dart';
import 'function_type_bounds_null_safe_lib.dart';
@@ -1,25 +0,0 @@
// 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.
// Requirements=nnbd-weak
import 'package:expect/expect.dart';
import 'function_type_bounds_null_safe_lib.dart';
main() {
// void fn<T extends Object>() is void Function<T extends Object?>()
// Should pass with weak checking because when the nullability information on
// Object and Object? are erased the type bounds are equivalent.
Expect.isTrue(fnWithNonNullObjectBound is fnTypeWithNullableObjectBound);
const test1 = fnWithNonNullObjectBound is fnTypeWithNullableObjectBound;
Expect.isTrue(test1);
// void fn<T extends Null>() is void Function<T extends Never>()
// Should pass with weak checking because Null becomes equivalent to
// the bottom type.
Expect.isTrue(fnWithNullBound is fnTypeWithNeverBound);
const test2 = fnWithNullBound is fnTypeWithNeverBound;
Expect.isTrue(test2);
}
@@ -2,7 +2,6 @@
// 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.
// Requirements=nnbd-strong
import 'package:expect/expect.dart';
int f({required int i}) {
@@ -3,7 +3,6 @@
// BSD-style license that can be found in the LICENSE file.
// VMOptions=--optimization_counter_threshold=10 --deterministic
// Requirements=nnbd-strong
// Verifies that null cannot be casted to Object.
// Regression test for https://github.com/dart-lang/sdk/issues/41272.
@@ -5,8 +5,6 @@
// Formatting can break multitests, so don't format them.
// dart format off
// Requirements=nnbd-strong
// Regression test for https://github.com/dart-lang/sdk/issues/41939
void checkme0<T>(T? t) {}
@@ -4,8 +4,6 @@
// VMOptions=--optimization_counter_threshold=10 --deterministic
// Requirements=nnbd-strong
import 'package:expect/expect.dart';
class C {}
@@ -2,8 +2,6 @@
// 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.
// Requirements=nnbd-strong
// Test that the trailing "?" is accepted after all type syntaxes. Verify that
// the compiler understands the resulting type to be nullable by trying to
// construct a list containing `null`. Verify that the runtime understands the
@@ -2,7 +2,6 @@
// 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.
// Requirements=nnbd-strong
import 'package:expect/expect.dart';
class Foo {
@@ -3,8 +3,6 @@
// BSD-style license that can be found in the LICENSE file.
import 'dart:async';
// Requirements=nnbd
import 'package:expect/expect.dart';
import 'futureOr_normalization_null_safe_lib.dart';
@@ -2,8 +2,6 @@
// 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.
// Requirements=nnbd
import 'package:expect/expect.dart';
import 'generic_function_type_equality_null_safe_lib.dart';
@@ -2,8 +2,6 @@
// 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.
// Requirements=nnbd
import "package:expect/expect.dart";
class A {}
@@ -16,8 +16,6 @@
// Also checks for types `T` where normalization removes or changes
// the `FutureOr`.
// Requirements=nnbd-strong
import "dart:async" show FutureOr;
import "package:expect/expect.dart";
@@ -2,8 +2,6 @@
// 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.
// Requirements=nnbd-strong
// In strong mode, `FutureOr` should be equivalent to the union of `Future<T>`
// and `T`.
-1
View File
@@ -3,7 +3,6 @@
// BSD-style license that can be found in the LICENSE file.
// In strong mode, `FutureOr` should be a valid type in most locations.
// Requirements=nnbd-strong
import 'dart:async';
import 'package:expect/expect.dart';
@@ -2,8 +2,6 @@
// 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.
// Requirements=nnbd-strong
import "package:expect/expect.dart";
main() {
@@ -1,16 +0,0 @@
// 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.
// Requirements=nnbd-weak
import "package:expect/expect.dart";
main() {
var shortDuration = Duration(milliseconds: 5);
Expect.isTrue(Future<int?>.delayed(shortDuration) is Future);
// In weak mode passing computation is not required because any type passed as
// the type argument can be nullable.
Expect.isTrue(Future<int>.delayed(shortDuration) is Future);
}
@@ -2,8 +2,6 @@
// 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.
// Requirements=nnbd-strong
// Test that external members returning numbers have correct semantics.
import 'dart:js_interop';
@@ -1,534 +0,0 @@
// Copyright (c) 2013, 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.
// VMOptions=--max_deoptimization_counter_threshold=1000 --optimization-counter-threshold=10 --no-background-compilation
// VMOptions=--no-intrinsify
// Requirements=nnbd-weak
// Library tag to be able to run in html test framework.
library float32x4_test;
import 'dart:typed_data';
import "package:expect/expect.dart";
testAdd() {
var m = new Float32x4(-1.0, -2.0, -3.0, -4.0);
var n = new Float32x4(1.0, 2.0, 3.0, 4.0);
var o = m + n;
Expect.equals(0.0, o.x);
Expect.equals(0.0, o.y);
Expect.equals(0.0, o.z);
Expect.equals(0.0, o.w);
}
testNegate() {
var m = new Float32x4(1.0, 2.0, -3.0, -4.0);
m = -m;
Expect.equals(-1.0, m.x);
Expect.equals(-2.0, m.y);
Expect.equals(3.0, m.z);
Expect.equals(4.0, m.w);
}
testSub() {
var m = new Float32x4(-1.0, -2.0, -3.0, -4.0);
var n = new Float32x4(1.0, 2.0, 3.0, 4.0);
var o = m - n;
Expect.equals(-2.0, o.x);
Expect.equals(-4.0, o.y);
Expect.equals(-6.0, o.z);
Expect.equals(-8.0, o.w);
}
testMul() {
var m = new Float32x4(-1.0, -2.0, -3.0, -4.0);
var n = new Float32x4(1.0, 2.0, 3.0, 4.0);
var o = m * n;
Expect.equals(-1.0, o.x);
Expect.equals(-4.0, o.y);
Expect.equals(-9.0, o.z);
Expect.equals(-16.0, o.w);
}
testDiv() {
var m = new Float32x4(-1.0, -2.0, -3.0, -4.0);
var n = new Float32x4(1.0, 2.0, 3.0, 4.0);
var o = m / n;
Expect.equals(-1.0, o.x);
Expect.equals(-1.0, o.y);
Expect.equals(-1.0, o.z);
Expect.equals(-1.0, o.w);
}
testComparison() {
var m = new Float32x4(1.0, 2.0, 0.1, 0.001);
var n = new Float32x4(2.0, 2.0, 0.001, 0.1);
var cmp;
cmp = m.lessThan(n);
Expect.equals(-1, cmp.x);
Expect.equals(0x0, cmp.y);
Expect.equals(0x0, cmp.z);
Expect.equals(-1, cmp.w);
cmp = m.lessThanOrEqual(n);
Expect.equals(-1, cmp.x);
Expect.equals(-1, cmp.y);
Expect.equals(0x0, cmp.z);
Expect.equals(-1, cmp.w);
cmp = m.equal(n);
Expect.equals(0x0, cmp.x);
Expect.equals(-1, cmp.y);
Expect.equals(0x0, cmp.z);
Expect.equals(0x0, cmp.w);
cmp = m.notEqual(n);
Expect.equals(-1, cmp.x);
Expect.equals(0x0, cmp.y);
Expect.equals(-1, cmp.z);
Expect.equals(-1, cmp.w);
cmp = m.greaterThanOrEqual(n);
Expect.equals(0x0, cmp.x);
Expect.equals(-1, cmp.y);
Expect.equals(-1, cmp.z);
Expect.equals(0x0, cmp.w);
cmp = m.greaterThan(n);
Expect.equals(0x0, cmp.x);
Expect.equals(0x0, cmp.y);
Expect.equals(-1, cmp.z);
Expect.equals(0x0, cmp.w);
}
testAbs() {
var m = new Float32x4(1.0, -2.0, 3.0, -4.0);
m = m.abs();
Expect.equals(1.0, m.x);
Expect.equals(2.0, m.y);
Expect.equals(3.0, m.z);
Expect.equals(4.0, m.w);
}
testScale() {
var m = new Float32x4(1.0, -2.0, 3.0, -4.0);
m = m.scale(20.0);
Expect.equals(20.0, m.x);
Expect.equals(-40.0, m.y);
Expect.equals(60.0, m.z);
Expect.equals(-80.0, m.w);
}
testClamp() {
var m = new Float32x4(1.0, -2.0, 3.0, -4.0);
var lo = new Float32x4(0.0, 0.0, 0.0, 0.0);
var hi = new Float32x4(2.0, 2.0, 2.0, 2.0);
m = m.clamp(lo, hi);
Expect.equals(1.0, m.x);
Expect.equals(0.0, m.y);
Expect.equals(2.0, m.z);
Expect.equals(0.0, m.w);
}
testShuffle() {
var m = new Float32x4(1.0, 2.0, 3.0, 4.0);
var xxxx = m.shuffle(Float32x4.xxxx);
Expect.equals(1.0, xxxx.x);
Expect.equals(1.0, xxxx.y);
Expect.equals(1.0, xxxx.z);
Expect.equals(1.0, xxxx.w);
var yyyy = m.shuffle(Float32x4.yyyy);
Expect.equals(2.0, yyyy.x);
Expect.equals(2.0, yyyy.y);
Expect.equals(2.0, yyyy.z);
Expect.equals(2.0, yyyy.w);
var zzzz = m.shuffle(Float32x4.zzzz);
Expect.equals(3.0, zzzz.x);
Expect.equals(3.0, zzzz.y);
Expect.equals(3.0, zzzz.z);
Expect.equals(3.0, zzzz.w);
var wwww = m.shuffle(Float32x4.wwww);
Expect.equals(4.0, wwww.x);
Expect.equals(4.0, wwww.y);
Expect.equals(4.0, wwww.z);
Expect.equals(4.0, wwww.w);
var wzyx = m.shuffle(Float32x4.wzyx);
Expect.equals(4.0, wzyx.x);
Expect.equals(3.0, wzyx.y);
Expect.equals(2.0, wzyx.z);
Expect.equals(1.0, wzyx.w);
var wwzz = m.shuffle(Float32x4.wwzz);
Expect.equals(4.0, wwzz.x);
Expect.equals(4.0, wwzz.y);
Expect.equals(3.0, wwzz.z);
Expect.equals(3.0, wwzz.w);
var xxyy = m.shuffle(Float32x4.xxyy);
Expect.equals(1.0, xxyy.x);
Expect.equals(1.0, xxyy.y);
Expect.equals(2.0, xxyy.z);
Expect.equals(2.0, xxyy.w);
var yyww = m.shuffle(Float32x4.yyww);
Expect.equals(2.0, yyww.x);
Expect.equals(2.0, yyww.y);
Expect.equals(4.0, yyww.z);
Expect.equals(4.0, yyww.w);
}
testMin() {
var m = new Float32x4(1.0, 2.0, 3.0, 4.0);
var n = new Float32x4(1.0, 0.0, 2.5, 5.0);
m = m.min(n);
Expect.equals(1.0, m.x);
Expect.equals(0.0, m.y);
Expect.equals(2.5, m.z);
Expect.equals(4.0, m.w);
}
testMax() {
var m = new Float32x4(1.0, 2.0, 3.0, 4.0);
var n = new Float32x4(1.0, 0.0, 2.5, 5.0);
m = m.max(n);
Expect.equals(1.0, m.x);
Expect.equals(2.0, m.y);
Expect.equals(3.0, m.z);
Expect.equals(5.0, m.w);
}
testSqrt() {
var m = new Float32x4(1.0, 4.0, 9.0, 16.0);
m = m.sqrt();
Expect.equals(1.0, m.x);
Expect.equals(2.0, m.y);
Expect.equals(3.0, m.z);
Expect.equals(4.0, m.w);
}
testReciprocal() {
var m = new Float32x4(1.0, 4.0, 9.0, 16.0);
m = m.reciprocal();
Expect.approxEquals(1.0, m.x, 0.001);
Expect.approxEquals(0.25, m.y, 0.001);
Expect.approxEquals(0.1111111, m.z, 0.001);
Expect.approxEquals(0.0625, m.w, 0.001);
}
testReciprocalSqrt() {
var m = new Float32x4(1.0, 0.25, 0.111111, 0.0625);
m = m.reciprocalSqrt();
Expect.approxEquals(1.0, m.x, 0.001);
Expect.approxEquals(2.0, m.y, 0.001);
Expect.approxEquals(3.0, m.z, 0.001);
Expect.approxEquals(4.0, m.w, 0.001);
}
testSelect() {
var m = new Int32x4.bool(true, true, false, false);
var t = new Float32x4(1.0, 2.0, 3.0, 4.0);
var f = new Float32x4(5.0, 6.0, 7.0, 8.0);
var s = m.select(t, f);
Expect.equals(1.0, s.x);
Expect.equals(2.0, s.y);
Expect.equals(7.0, s.z);
Expect.equals(8.0, s.w);
}
testConversions() {
var m = new Int32x4(0x3F800000, 0x40000000, 0x40400000, 0x40800000);
var n = new Float32x4.fromInt32x4Bits(m);
Expect.equals(1.0, n.x);
Expect.equals(2.0, n.y);
Expect.equals(3.0, n.z);
Expect.equals(4.0, n.w);
n = new Float32x4(5.0, 6.0, 7.0, 8.0);
m = new Int32x4.fromFloat32x4Bits(n);
Expect.equals(0x40A00000, m.x);
Expect.equals(0x40C00000, m.y);
Expect.equals(0x40E00000, m.z);
Expect.equals(0x41000000, m.w);
// Flip sign using bit-wise operators.
n = new Float32x4(9.0, 10.0, 11.0, 12.0);
m = new Int32x4(0x80000000, 0x80000000, 0x80000000, 0x80000000);
var nMask = new Int32x4.fromFloat32x4Bits(n);
nMask = nMask ^ m; // flip sign.
n = new Float32x4.fromInt32x4Bits(nMask);
Expect.equals(-9.0, n.x);
Expect.equals(-10.0, n.y);
Expect.equals(-11.0, n.z);
Expect.equals(-12.0, n.w);
nMask = new Int32x4.fromFloat32x4Bits(n);
nMask = nMask ^ m; // flip sign.
n = new Float32x4.fromInt32x4Bits(nMask);
Expect.equals(9.0, n.x);
Expect.equals(10.0, n.y);
Expect.equals(11.0, n.z);
Expect.equals(12.0, n.w);
}
testBitOperators() {
var m = new Int32x4(0xAAAAAAA, 0xAAAAAAA, 0xAAAAAAA, 0xAAAAAAA);
var n = new Int32x4(0x5555555, 0x5555555, 0x5555555, 0x5555555);
Expect.equals(0xAAAAAAA, m.x);
Expect.equals(0xAAAAAAA, m.y);
Expect.equals(0xAAAAAAA, m.z);
Expect.equals(0xAAAAAAA, m.w);
Expect.equals(0x5555555, n.x);
Expect.equals(0x5555555, n.y);
Expect.equals(0x5555555, n.z);
Expect.equals(0x5555555, n.w);
Expect.equals(true, n.flagX);
Expect.equals(true, n.flagY);
Expect.equals(true, n.flagZ);
Expect.equals(true, n.flagW);
var o = m | n; // or
Expect.equals(0xFFFFFFF, o.x);
Expect.equals(0xFFFFFFF, o.y);
Expect.equals(0xFFFFFFF, o.z);
Expect.equals(0xFFFFFFF, o.w);
Expect.equals(true, o.flagX);
Expect.equals(true, o.flagY);
Expect.equals(true, o.flagZ);
Expect.equals(true, o.flagW);
o = m & n; // and
Expect.equals(0x0, o.x);
Expect.equals(0x0, o.y);
Expect.equals(0x0, o.z);
Expect.equals(0x0, o.w);
n = n.withX(0xAAAAAAA);
n = n.withY(0xAAAAAAA);
n = n.withZ(0xAAAAAAA);
n = n.withW(0xAAAAAAA);
Expect.equals(0xAAAAAAA, n.x);
Expect.equals(0xAAAAAAA, n.y);
Expect.equals(0xAAAAAAA, n.z);
Expect.equals(0xAAAAAAA, n.w);
o = m ^ n; // xor
Expect.equals(0x0, o.x);
Expect.equals(0x0, o.y);
Expect.equals(0x0, o.z);
Expect.equals(0x0, o.w);
Expect.equals(false, o.flagX);
Expect.equals(false, o.flagY);
Expect.equals(false, o.flagZ);
Expect.equals(false, o.flagW);
}
testSetters() {
var f = new Float32x4.zero();
Expect.equals(0.0, f.x);
Expect.equals(0.0, f.y);
Expect.equals(0.0, f.z);
Expect.equals(0.0, f.w);
f = f.withX(4.0);
Expect.equals(4.0, f.x);
f = f.withY(3.0);
Expect.equals(3.0, f.y);
f = f.withZ(2.0);
Expect.equals(2.0, f.z);
f = f.withW(1.0);
Expect.equals(1.0, f.w);
f = new Float32x4.zero();
f = f.withX(4.0).withZ(2.0).withW(1.0).withY(3.0);
Expect.equals(4.0, f.x);
Expect.equals(3.0, f.y);
Expect.equals(2.0, f.z);
Expect.equals(1.0, f.w);
var m = new Int32x4.bool(false, false, false, false);
Expect.equals(false, m.flagX);
Expect.equals(false, m.flagY);
Expect.equals(false, m.flagZ);
Expect.equals(false, m.flagW);
m = m.withFlagX(true);
Expect.equals(true, m.flagX);
Expect.equals(false, m.flagY);
Expect.equals(false, m.flagZ);
Expect.equals(false, m.flagW);
m = m.withFlagY(true);
Expect.equals(true, m.flagX);
Expect.equals(true, m.flagY);
Expect.equals(false, m.flagZ);
Expect.equals(false, m.flagW);
m = m.withFlagZ(true);
Expect.equals(true, m.flagX);
Expect.equals(true, m.flagY);
Expect.equals(true, m.flagZ);
Expect.equals(false, m.flagW);
m = m.withFlagW(true);
Expect.equals(true, m.flagX);
Expect.equals(true, m.flagY);
Expect.equals(true, m.flagZ);
Expect.equals(true, m.flagW);
}
testGetters() {
var f = new Float32x4(1.0, 2.0, 3.0, 4.0);
Expect.equals(1.0, f.x);
Expect.equals(2.0, f.y);
Expect.equals(3.0, f.z);
Expect.equals(4.0, f.w);
var m = new Int32x4.bool(false, true, true, false);
Expect.equals(false, m.flagX);
Expect.equals(true, m.flagY);
Expect.equals(true, m.flagZ);
Expect.equals(false, m.flagW);
}
void testSplat() {
var f = new Float32x4.splat(2.0);
Expect.equals(2.0, f.x);
Expect.equals(2.0, f.y);
Expect.equals(2.0, f.z);
Expect.equals(2.0, f.w);
}
void testZero() {
var f = new Float32x4.zero();
Expect.equals(0.0, f.x);
Expect.equals(0.0, f.y);
Expect.equals(0.0, f.z);
Expect.equals(0.0, f.w);
}
void testConstructor() {
var f = new Float32x4(1.0, 2.0, 3.0, 4.0);
Expect.equals(1.0, f.x);
Expect.equals(2.0, f.y);
Expect.equals(3.0, f.z);
Expect.equals(4.0, f.w);
}
void testBadArguments() {
// This test runs in weak checking mode, so `e as double` will complete
// normally when `e` evaluates to the null object. This means that we do
// not get the `TypeError` that we would have in strong checking mode, but
// we happen to get an `ArgumentError` from the body of the constructor.
dynamic dynamicNull = null;
Expect.throwsArgumentError(() => new Float32x4(dynamicNull, 2.0, 3.0, 4.0));
Expect.throwsArgumentError(() => new Float32x4(1.0, dynamicNull, 3.0, 4.0));
Expect.throwsArgumentError(() => new Float32x4(1.0, 2.0, dynamicNull, 4.0));
Expect.throwsArgumentError(() => new Float32x4(1.0, 2.0, 3.0, dynamicNull));
bool isTypeError(e) => e is TypeError;
// Use local variable typed as "dynamic" to avoid static warnings.
// When `e` evaluates to a string, `e as double` will fail, so we do get
// the `TypeError`.
dynamic str = "foo";
Expect.throws(() => new Float32x4(str, 2.0, 3.0, 4.0), isTypeError);
Expect.throws(() => new Float32x4(1.0, str, 3.0, 4.0), isTypeError);
Expect.throws(() => new Float32x4(1.0, 2.0, str, 4.0), isTypeError);
Expect.throws(() => new Float32x4(1.0, 2.0, 3.0, str), isTypeError);
}
void testSpecialValues() {
/// Same as Expect.identical, but also works with NaNs and -0.0 for dart2js.
void checkEquals(expected, actual) {
if (expected.isNaN) {
Expect.isTrue(actual.isNaN);
} else if (expected == 0.0 && expected.isNegative) {
Expect.isTrue(actual == 0.0 && actual.isNegative);
} else {
Expect.equals(expected, actual);
}
}
var pairs = [
[0.0, 0.0],
[5e-324, 0.0],
[2.225073858507201e-308, 0.0],
[2.2250738585072014e-308, 0.0],
[0.9999999999999999, 1.0],
[1.0, 1.0],
[1.0000000000000002, 1.0],
[4294967295.0, 4294967296.0],
[4294967296.0, 4294967296.0],
[4503599627370495.5, 4503599627370496.0],
[9007199254740992.0, 9007199254740992.0],
[1.7976931348623157e+308, double.infinity],
[0.49999999999999994, 0.5],
[4503599627370497.0, 4503599627370496.0],
[9007199254740991.0, 9007199254740992.0],
[double.infinity, double.infinity],
[double.nan, double.nan],
];
var conserved = [
1.401298464324817e-45,
1.1754942106924411e-38,
1.1754943508222875e-38,
0.9999999403953552,
1.0000001192092896,
8388607.5,
8388608.0,
3.4028234663852886e+38,
8388609.0,
16777215.0,
];
var minusPairs = pairs.map((pair) {
return [-pair[0], -pair[1]];
});
var conservedPairs = conserved.map((value) => [value, value]);
var allTests = [pairs, minusPairs, conservedPairs].expand((x) => x);
for (var pair in allTests) {
var input = pair[0];
var expected = pair[1];
var f;
f = new Float32x4(input, 2.0, 3.0, 4.0);
checkEquals(expected, f.x);
Expect.equals(2.0, f.y);
Expect.equals(3.0, f.z);
Expect.equals(4.0, f.w);
f = new Float32x4(1.0, input, 3.0, 4.0);
Expect.equals(1.0, f.x);
checkEquals(expected, f.y);
Expect.equals(3.0, f.z);
Expect.equals(4.0, f.w);
f = new Float32x4(1.0, 2.0, input, 4.0);
Expect.equals(1.0, f.x);
Expect.equals(2.0, f.y);
checkEquals(expected, f.z);
Expect.equals(4.0, f.w);
f = new Float32x4(1.0, 2.0, 3.0, input);
Expect.equals(1.0, f.x);
Expect.equals(2.0, f.y);
Expect.equals(3.0, f.z);
checkEquals(expected, f.w);
}
}
main() {
for (int i = 0; i < 20; i++) {
testConstructor();
testSplat();
testZero();
testAdd();
testGetters();
testSetters();
testBitOperators();
testConversions();
testSelect();
testShuffle();
testSub();
testNegate();
testMul();
testDiv();
testComparison();
testScale();
testClamp();
testAbs();
testMin();
testMax();
testSqrt();
testReciprocal();
testReciprocalSqrt();
testBadArguments();
testSpecialValues();
}
}
-2
View File
@@ -4,8 +4,6 @@
// VMOptions=--max_deoptimization_counter_threshold=1000 --optimization-counter-threshold=10 --no-background-compilation
// VMOptions=--no-intrinsify
// Requirements=nnbd-strong
library int32x4_test;
import 'dart:typed_data';
@@ -1,88 +0,0 @@
// Copyright (c) 2014, 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.
// VMOptions=--max_deoptimization_counter_threshold=1000 --optimization-counter-threshold=10 --no-background-compilation
// VMOptions=--no-intrinsify
// Requirements=nnbd-weak
library int32x4_test;
import 'dart:typed_data';
import 'package:expect/expect.dart';
void testBadArguments() {
// This test runs in weak checking mode, so `e as int` will complete
// normally when `e` evaluates to the null object. This means that we do
// not get the `TypeError` that we would have in strong checking mode, but
// we happen to get an `ArgumentError` from the body of the constructor.
dynamic dynamicNull = null;
Expect.throwsArgumentError(() => new Int32x4(dynamicNull, 2, 3, 4));
Expect.throwsArgumentError(() => new Int32x4(1, dynamicNull, 3, 4));
Expect.throwsArgumentError(() => new Int32x4(1, 2, dynamicNull, 4));
Expect.throwsArgumentError(() => new Int32x4(1, 2, 3, dynamicNull));
bool isTypeError(e) => e is TypeError;
// Use a local variable typed as dynamic to avoid static warnings.
dynamic str = "foo";
Expect.throws(() => new Int32x4(str, 2, 3, 4), isTypeError);
Expect.throws(() => new Int32x4(1, str, 3, 4), isTypeError);
Expect.throws(() => new Int32x4(1, 2, str, 4), isTypeError);
Expect.throws(() => new Int32x4(1, 2, 3, str), isTypeError);
// Use a local variable typed as dynamic to avoid static warnings.
dynamic d = 0.5;
Expect.throws(() => new Int32x4(d, 2, 3, 4), isTypeError);
Expect.throws(() => new Int32x4(1, d, 3, 4), isTypeError);
Expect.throws(() => new Int32x4(1, 2, d, 4), isTypeError);
Expect.throws(() => new Int32x4(1, 2, 3, d), isTypeError);
}
void testBigArguments() {
var tests = [
[0x8901234567890, 0x34567890],
[0x89012A4567890, -1537836912],
[0x80000000, -2147483648],
[-0x80000000, -2147483648],
[0x7fffffff, 2147483647],
[-0x7fffffff, -2147483647],
];
var int32x4;
for (var test in tests) {
var input = test[0];
var expected = test[1];
int32x4 = new Int32x4(input, 2, 3, 4);
Expect.equals(expected, int32x4.x);
Expect.equals(2, int32x4.y);
Expect.equals(3, int32x4.z);
Expect.equals(4, int32x4.w);
int32x4 = new Int32x4(1, input, 3, 4);
Expect.equals(1, int32x4.x);
Expect.equals(expected, int32x4.y);
Expect.equals(3, int32x4.z);
Expect.equals(4, int32x4.w);
int32x4 = new Int32x4(1, 2, input, 4);
Expect.equals(1, int32x4.x);
Expect.equals(2, int32x4.y);
Expect.equals(expected, int32x4.z);
Expect.equals(4, int32x4.w);
int32x4 = new Int32x4(1, 2, 3, input);
Expect.equals(1, int32x4.x);
Expect.equals(2, int32x4.y);
Expect.equals(3, int32x4.z);
Expect.equals(expected, int32x4.w);
}
}
main() {
for (int i = 0; i < 20; i++) {
testBigArguments();
testBadArguments();
}
}
@@ -2,8 +2,6 @@
// 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.
// Requirements=nnbd-strong
// Many other tests will check that static nullability checks are applied to
// actual arguments of regular function invocations. This test is still not
// redundant, because it involves a built-in type and methods subject to
@@ -2,8 +2,6 @@
// 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.
// Requirements=nnbd-strong
import 'dart:typed_data';
import "package:expect/expect.dart";
@@ -1,169 +0,0 @@
// Copyright (c) 2019, 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.
// Requirements=nnbd-weak
import 'dart:typed_data';
import "package:expect/expect.dart";
bool throwsSomeError(void Function() f) {
try {
f();
} catch (e) {
return e is TypeError ||
e is NoSuchMethodError ||
e is ArgumentError ||
e is AssertionError;
}
return false;
}
main() {
dynamic dynamicNull = null;
// Float32x4
final float32x4 = Float32x4(0.0, 0.0, 0.0, 0.0);
Expect.equals(true, throwsSomeError(() => float32x4 + dynamicNull));
Expect.equals(true, throwsSomeError(() => float32x4 - dynamicNull));
Expect.equals(true, throwsSomeError(() => float32x4 * dynamicNull));
Expect.equals(true, throwsSomeError(() => float32x4 / dynamicNull));
Expect.equals(true, throwsSomeError(() => float32x4.lessThan(dynamicNull)));
Expect.equals(
true,
throwsSomeError(() => float32x4.lessThanOrEqual(dynamicNull)),
);
Expect.equals(
true,
throwsSomeError(() => float32x4.greaterThan(dynamicNull)),
);
Expect.equals(
true,
throwsSomeError(() => float32x4.greaterThanOrEqual(dynamicNull)),
);
Expect.equals(true, throwsSomeError(() => float32x4.equal(dynamicNull)));
Expect.equals(true, throwsSomeError(() => float32x4.notEqual(dynamicNull)));
Expect.equals(true, throwsSomeError(() => float32x4.scale(dynamicNull)));
Expect.equals(
true,
throwsSomeError(() => float32x4.clamp(dynamicNull, float32x4)),
);
Expect.equals(
true,
throwsSomeError(() => float32x4.clamp(float32x4, dynamicNull)),
);
Expect.equals(true, throwsSomeError(() => float32x4.shuffle(dynamicNull)));
Expect.equals(
true,
throwsSomeError(() => float32x4.shuffleMix(float32x4, dynamicNull)),
);
Expect.equals(
true,
throwsSomeError(() => float32x4.shuffleMix(dynamicNull, 0)),
);
Expect.equals(true, throwsSomeError(() => float32x4.withX(dynamicNull)));
Expect.equals(true, throwsSomeError(() => float32x4.withY(dynamicNull)));
Expect.equals(true, throwsSomeError(() => float32x4.withZ(dynamicNull)));
Expect.equals(true, throwsSomeError(() => float32x4.withW(dynamicNull)));
Expect.equals(true, throwsSomeError(() => float32x4.min(dynamicNull)));
Expect.equals(true, throwsSomeError(() => float32x4.max(dynamicNull)));
Expect.equals(
true,
throwsSomeError(() => Float32x4(dynamicNull, 0.0, 0.0, 0.0)),
);
Expect.equals(
true,
throwsSomeError(() => Float32x4(0.0, dynamicNull, 0.0, 0.0)),
);
Expect.equals(
true,
throwsSomeError(() => Float32x4(0.0, 0.0, dynamicNull, 0.0)),
);
Expect.equals(
true,
throwsSomeError(() => Float32x4(0.0, 0.0, 0.0, dynamicNull)),
);
// Float32x4.splat
Expect.equals(true, throwsSomeError(() => Float32x4.splat(dynamicNull)));
// Float64x2
final float64x2 = Float64x2(0.0, 0.0);
Expect.equals(true, throwsSomeError(() => float64x2 + dynamicNull));
Expect.equals(true, throwsSomeError(() => float64x2 - dynamicNull));
Expect.equals(true, throwsSomeError(() => float64x2 * dynamicNull));
Expect.equals(true, throwsSomeError(() => float64x2 / dynamicNull));
Expect.equals(true, throwsSomeError(() => float64x2.scale(dynamicNull)));
Expect.equals(
true,
throwsSomeError(() => float64x2.clamp(dynamicNull, float64x2)),
);
Expect.equals(
true,
throwsSomeError(() => float64x2.clamp(float64x2, dynamicNull)),
);
Expect.equals(true, throwsSomeError(() => float64x2.withX(dynamicNull)));
Expect.equals(true, throwsSomeError(() => float64x2.withY(dynamicNull)));
Expect.equals(true, throwsSomeError(() => Float64x2(dynamicNull, 0.0)));
Expect.equals(true, throwsSomeError(() => Float64x2(0.0, dynamicNull)));
Expect.equals(true, throwsSomeError(() => float64x2.min(dynamicNull)));
Expect.equals(true, throwsSomeError(() => float64x2.max(dynamicNull)));
// Float64x2.splat
Expect.equals(true, throwsSomeError(() => Float64x2.splat(dynamicNull)));
// Int32x4
final int32x4 = Int32x4(0, 0, 0, 0);
Expect.equals(true, throwsSomeError(() => int32x4 + dynamicNull));
Expect.equals(true, throwsSomeError(() => int32x4 - dynamicNull));
Expect.equals(true, throwsSomeError(() => int32x4 ^ dynamicNull));
Expect.equals(true, throwsSomeError(() => int32x4 & dynamicNull));
Expect.equals(true, throwsSomeError(() => int32x4 | dynamicNull));
Expect.equals(true, throwsSomeError(() => int32x4.shuffle(dynamicNull)));
Expect.equals(
true,
throwsSomeError(() => int32x4.shuffleMix(int32x4, dynamicNull)),
);
Expect.equals(
true,
throwsSomeError(() => int32x4.shuffleMix(dynamicNull, 0)),
);
Expect.equals(true, throwsSomeError(() => int32x4.withX(dynamicNull)));
Expect.equals(true, throwsSomeError(() => int32x4.withY(dynamicNull)));
Expect.equals(true, throwsSomeError(() => int32x4.withZ(dynamicNull)));
Expect.equals(true, throwsSomeError(() => int32x4.withW(dynamicNull)));
Expect.equals(true, throwsSomeError(() => int32x4.withFlagX(dynamicNull)));
Expect.equals(true, throwsSomeError(() => int32x4.withFlagY(dynamicNull)));
Expect.equals(true, throwsSomeError(() => int32x4.withFlagZ(dynamicNull)));
Expect.equals(true, throwsSomeError(() => int32x4.withFlagW(dynamicNull)));
Expect.equals(true, throwsSomeError(() => Int32x4(dynamicNull, 0, 0, 0)));
Expect.equals(true, throwsSomeError(() => Int32x4(0, dynamicNull, 0, 0)));
Expect.equals(true, throwsSomeError(() => Int32x4(0, 0, dynamicNull, 0)));
Expect.equals(true, throwsSomeError(() => Int32x4(0, 0, 0, dynamicNull)));
Expect.equals(
true,
throwsSomeError(() => int32x4.select(dynamicNull, float32x4)),
);
Expect.equals(
true,
throwsSomeError(() => int32x4.select(float32x4, dynamicNull)),
);
// Int32x4.bool
Expect.equals(
true,
throwsSomeError(() => Int32x4.bool(dynamicNull, false, false, false)),
);
Expect.equals(
true,
throwsSomeError(() => Int32x4.bool(false, dynamicNull, false, false)),
);
Expect.equals(
true,
throwsSomeError(() => Int32x4.bool(false, false, dynamicNull, false)),
);
Expect.equals(
true,
throwsSomeError(() => Int32x4.bool(false, false, false, dynamicNull)),
);
}
@@ -1,27 +0,0 @@
// Copyright (c) 2015, 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.
// Packages=empty_lines.packages
// This test verifies handling of legacy .packages file and cannot be run in
// null safety (strong) mode as strong mode needs new package_config.json.
// Requirements=nnbd-weak
library empty_lines_test;
import 'package:foo/foo.dart' as foo;
import 'package:bar/bar.dart' as bar;
import 'package:baz/baz.dart' as baz;
main() {
if (foo.foo != 'foo') {
throw new Exception('package "foo" was not resolved correctly');
}
if (bar.bar != 'bar') {
throw new Exception('package "bar" was not resolved correctly');
}
if (baz.baz != 'baz') {
throw new Exception('package "baz" was not resolved correctly');
}
}
@@ -1,22 +0,0 @@
// Copyright (c) 2015, 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.
// Formatting can break multitests, so don't format them.
// dart format off
// Packages=empty_package_dir.packages
// This test verifies handling of legacy .packages file and cannot be run in
// null safety (strong) mode as strong mode needs new package_config.json.
// Requirements=nnbd-weak
// In this test, we give a packages file that associates the package 'foo' with
// the empty string. This causes both the VM and dart2js to resolve
// 'package:foo' imports relative to the root directory. So the import statement
// `import 'package:foo/foo.dart'` is equivalent to `import '/foo.dart'`.
library empty_package_dir_test;
import 'package:foo/foo.dart'; //# 01: compile-time error
main() {}
@@ -1,27 +0,0 @@
// Copyright (c) 2015, 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.
// Packages=mixed_line_ends.packages
// This test verifies handling of legacy .packages file and cannot be run in
// null safety (strong) mode as strong mode needs new package_config.json.
// Requirements=nnbd-weak
library mixed_line_ends_test;
import 'package:foo/foo.dart' as foo;
import 'package:bar/bar.dart' as bar;
import 'package:baz/baz.dart' as baz;
main() {
if (foo.foo != 'foo') {
throw new Exception('package "foo" was not resolved correctly');
}
if (bar.bar != 'bar') {
throw new Exception('package "bar" was not resolved correctly');
}
if (baz.baz != 'baz') {
throw new Exception('package "baz" was not resolved correctly');
}
}
@@ -2,8 +2,6 @@
// 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.
// Requirements=nnbd-strong
import 'package:expect/expect.dart';
import 'deferred_apply_lib.dart' deferred as lib;
@@ -2,8 +2,6 @@
// 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.
// Requirements=nnbd
import 'dart:_rti' as rti;
import 'dart:_foreign_helper' show JS;
import "package:expect/expect.dart";
@@ -2,7 +2,6 @@
// 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.
// Requirements=nnbd-strong
// dart2jsOptions=--no-native-null-assertions
import 'non_web_library_interfaces.dart';
@@ -2,7 +2,6 @@
// 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.
// Requirements=nnbd-strong
// dart2jsOptions=--no-native-null-assertions
import 'null_assertions_test_lib.dart';
@@ -2,7 +2,6 @@
// 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.
// Requirements=nnbd-strong
// dart2jsOptions=--native-null-assertions
import 'non_web_library_interfaces.dart';
@@ -2,7 +2,6 @@
// 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.
// Requirements=nnbd-strong
// dart2jsOptions=-O3 --native-null-assertions
import 'null_assertions_test_lib.dart';
@@ -1,17 +0,0 @@
// Copyright (c) 2023, 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.
// Requirements=nnbd-weak
// dart2jsOptions=--native-null-assertions
import 'null_assertions_test_lib.dart';
import 'web_library_interfaces.dart';
void main() {
// To avoid a breaking change, we don't enable checks even if the user passes
// the flag in unsound mode.
var flagEnabled = false;
testNativeNullAssertions(flagEnabled);
testJSInvocationNullAssertions(flagEnabled);
}
@@ -2,7 +2,6 @@
// 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.
// Requirements=nnbd-strong
// dart2jsOptions=--native-null-assertions
import 'null_assertions_test_lib.dart';
@@ -2,7 +2,6 @@
// 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.
// Requirements=nnbd-strong
// dart2jsOptions=-O3
import 'null_assertions_test_lib.dart';
@@ -2,7 +2,6 @@
// 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.
// Requirements=nnbd-strong
// dart2jsOptions=-O1
import 'null_assertions_test_lib.dart';
-2
View File
@@ -2,8 +2,6 @@
// 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.
// Requirements=nnbd-strong
import 'package:expect/expect.dart';
class Foo<T> {