Rename is{Strong,Weak}Mode to has{Sound,Unsound}NullSafety

Change-Id: If3912d75c5f89a741299b2fae4299d01ac928eec
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/170424
Reviewed-by: Lasse R.H. Nielsen <lrn@google.com>
Reviewed-by: Michael Thomsen <mit@google.com>
Reviewed-by: Mayank Patke <fishythefish@google.com>
Commit-Queue: Erik Ernst <eernst@google.com>
This commit is contained in:
Erik Ernst 2020-11-05 14:26:53 +00:00 committed by commit-bot@chromium.org
parent 633c5389a5
commit 3a7eeb6315
30 changed files with 68 additions and 58 deletions

View file

@ -10,11 +10,11 @@ library expect;
import 'package:meta/meta.dart'; import 'package:meta/meta.dart';
/// Whether the program is running with weak null safety checking. /// Whether the program is running without sound null safety.
bool get isWeakMode => const <Null>[] is List<Object>; bool get hasUnsoundNullSafety => const <Null>[] is List<Object>;
/// Whether the program is running with strong null safety checking. /// Whether the program is running with sound null safety.
bool get isStrongMode => !isWeakMode; bool get hasSoundNullSafety => !hasUnsoundNullSafety;
/** /**
* Expect is used for tests that do not want to make use of the * Expect is used for tests that do not want to make use of the
@ -620,11 +620,11 @@ class Expect {
/// Checks that [f] throws an appropriate error on a null argument. /// Checks that [f] throws an appropriate error on a null argument.
/// ///
/// In strong mode, this is expected to be a [TypeError] when casting the /// With sound null safety, this is expected to be a [TypeError] when casting
/// `null` to some non-nullable type. In weak mode, that cast is ignored and /// the `null` to some non-nullable type. In weak mode, that cast is ignored
/// some later explicit validation should handle it and [ArgumentError]. /// and some later explicit validation should handle it and [ArgumentError].
static void throwsNullCheckError(void f()) { static void throwsNullCheckError(void f()) {
if (isStrongMode) { if (hasSoundNullSafety) {
throwsTypeError(f); throwsTypeError(f);
} else { } else {
throwsArgumentError(f); throwsArgumentError(f);

View file

@ -14,6 +14,6 @@ final bool strong = () {
}(); }();
void main() { void main() {
Expect.equals(strong, isStrongMode); Expect.equals(strong, hasSoundNullSafety);
Expect.equals(!strong, isWeakMode); Expect.equals(!strong, hasUnsoundNullSafety);
} }

View file

@ -89,7 +89,7 @@ main(List<String> args) {
Expect.throws( Expect.throws(
() => 9.81 - doubleNull, () => 9.81 - doubleNull,
(e) => isWeakMode (e) => hasUnsoundNullSafety
? (e is NoSuchMethodError && ? (e is NoSuchMethodError &&
// If '-' is specialized. // If '-' is specialized.
(e.toString().startsWith( (e.toString().startsWith(

View file

@ -52,8 +52,10 @@ main(List<String> args) {
Expect.throws(() => doubleNull + 2.17, (e) => e is NoSuchMethodError); Expect.throws(() => doubleNull + 2.17, (e) => e is NoSuchMethodError);
Expect.throws(() => 9.81 - doubleNull, Expect.throws(
(e) => isWeakMode ? (e is NoSuchMethodError) : (e is TypeError)); () => 9.81 - doubleNull,
(e) =>
hasUnsoundNullSafety ? (e is NoSuchMethodError) : (e is TypeError));
Expect.throws(() => intNull * 7, (e) => e is NoSuchMethodError); Expect.throws(() => intNull * 7, (e) => e is NoSuchMethodError);
} }

View file

@ -107,7 +107,7 @@ main() async {
throwsIfCummulativeListIsTooLargeOn32bitPlatform(); throwsIfCummulativeListIsTooLargeOn32bitPlatform();
dynamic myNull; dynamic myNull;
if (isWeakMode) { if (hasUnsoundNullSafety) {
Expect.throwsArgumentError(() => TransferableTypedData.fromList(myNull)); Expect.throwsArgumentError(() => TransferableTypedData.fromList(myNull));
Expect.throwsArgumentError(() => TransferableTypedData.fromList([myNull])); Expect.throwsArgumentError(() => TransferableTypedData.fromList([myNull]));
Expect.throwsArgumentError( Expect.throwsArgumentError(

View file

@ -10,7 +10,7 @@ class RegExpAllMatchesTest {
static testIterator() { static testIterator() {
var matches = new RegExp("foo").allMatches("foo foo"); var matches = new RegExp("foo").allMatches("foo foo");
Iterator it = matches.iterator; Iterator it = matches.iterator;
if (isStrongMode) { if (hasSoundNullSafety) {
Expect.throws(() => it.current); Expect.throws(() => it.current);
} else { } else {
Expect.isNull(it.current); Expect.isNull(it.current);

View file

@ -51,11 +51,13 @@ main() {
// Subtype may not redeclare optional parameters as required // Subtype may not redeclare optional parameters as required
rti2 = rti.testingUniverseEval(universe, "@(A,{a!A,b!A,c!A})"); rti2 = rti.testingUniverseEval(universe, "@(A,{a!A,b!A,c!A})");
Expect.equals(isWeakMode, rti.testingIsSubtype(universe, rti2, rti1)); Expect.equals(
hasUnsoundNullSafety, rti.testingIsSubtype(universe, rti2, rti1));
// Subtype may not declare new required named parameters // Subtype may not declare new required named parameters
rti2 = rti.testingUniverseEval(universe, "@(A,{a!A,b:A,c!A,d!A})"); rti2 = rti.testingUniverseEval(universe, "@(A,{a!A,b:A,c!A,d!A})");
Expect.equals(isWeakMode, rti.testingIsSubtype(universe, rti2, rti1)); Expect.equals(
hasUnsoundNullSafety, rti.testingIsSubtype(universe, rti2, rti1));
// Rti.toString() appears as expected // Rti.toString() appears as expected
Expect.equals('(B, {required B a, B b, required B c}) => dynamic', Expect.equals('(B, {required B a, B b, required B c}) => dynamic',

View file

@ -78,7 +78,7 @@ void testTopTypes() {
} }
void testNull() { void testNull() {
if (isStrongMode) { if (hasSoundNullSafety) {
unrelated(nullName, 'int'); unrelated(nullName, 'int');
unrelated(nullName, 'Iterable<CodeUnits>'); unrelated(nullName, 'Iterable<CodeUnits>');
unrelated(nullName, objectName); unrelated(nullName, objectName);
@ -93,7 +93,7 @@ void testNull() {
void testBottom() { void testBottom() {
String never = '0&'; String never = '0&';
if (isStrongMode) { if (hasSoundNullSafety) {
strictSubtype(never, nullName); strictSubtype(never, nullName);
} else { } else {
equivalent(never, nullName); equivalent(never, nullName);

View file

@ -51,11 +51,13 @@ main() {
// Subtype may not redeclare optional parameters as required // Subtype may not redeclare optional parameters as required
rti2 = rti.testingUniverseEval(universe, "@(A,{a!A,b!A,c!A})"); rti2 = rti.testingUniverseEval(universe, "@(A,{a!A,b!A,c!A})");
Expect.equals(isWeakMode, rti.testingIsSubtype(universe, rti2, rti1)); Expect.equals(
hasUnsoundNullSafety, rti.testingIsSubtype(universe, rti2, rti1));
// Subtype may not declare new required named parameters // Subtype may not declare new required named parameters
rti2 = rti.testingUniverseEval(universe, "@(A,{a!A,b:A,c!A,d!A})"); rti2 = rti.testingUniverseEval(universe, "@(A,{a!A,b:A,c!A,d!A})");
Expect.equals(isWeakMode, rti.testingIsSubtype(universe, rti2, rti1)); Expect.equals(
hasUnsoundNullSafety, rti.testingIsSubtype(universe, rti2, rti1));
// Rti.toString() appears as expected // Rti.toString() appears as expected
Expect.equals('(B, {required B a, B b, required B c}) => dynamic', Expect.equals('(B, {required B a, B b, required B c}) => dynamic',

View file

@ -39,7 +39,7 @@ main() {
new D<String, bool>().test('bool', true); new D<String, bool>().test('bool', true);
new D<bool, int>().test('int', false); new D<bool, int>().test('int', false);
new D<Object, Object>().test('Object', false); new D<Object, Object>().test('Object', false);
new D<Null, Null>().test('Null', isWeakMode); new D<Null, Null>().test('Null', hasUnsoundNullSafety);
new D<Never, Never>().test('Never', true); new D<Never, Never>().test('Never', true);
new D<dynamic, dynamic>().test('dynamic', false); new D<dynamic, dynamic>().test('dynamic', false);
} }

View file

@ -41,7 +41,7 @@ main() {
new D<String, bool>().test('bool', true); new D<String, bool>().test('bool', true);
new D<bool, int>().test('int', false); new D<bool, int>().test('int', false);
new D<Object, Object>().test('Object', false); new D<Object, Object>().test('Object', false);
new D<Null, Null>().test('Null', isWeakMode); new D<Null, Null>().test('Null', hasUnsoundNullSafety);
new D<Never, Never>().test('Never', true); new D<Never, Never>().test('Never', true);
new D<dynamic, dynamic>().test('dynamic', false); new D<dynamic, dynamic>().test('dynamic', false);
} }

View file

@ -42,6 +42,6 @@ main() {
new C<int>().test('int', false); new C<int>().test('int', false);
new C<Object>().test('Object', false); new C<Object>().test('Object', false);
new C<dynamic>().test('dynamic', false); new C<dynamic>().test('dynamic', false);
new C<Null>().test('Null', isWeakMode); new C<Null>().test('Null', hasUnsoundNullSafety);
new C<Never>().test('Never', true); new C<Never>().test('Never', true);
} }

View file

@ -26,7 +26,7 @@ void bar(int i) {}
void main() { void main() {
new Class<dynamic>().test(false, bar, "dynamic"); new Class<dynamic>().test(false, bar, "dynamic");
new Class<Object>().test(false, bar, "Object"); new Class<Object>().test(false, bar, "Object");
new Class<Null>().test(isWeakMode, bar, "Null"); new Class<Null>().test(hasUnsoundNullSafety, bar, "Null");
new Class<Never>().test(true, bar, "Never"); new Class<Never>().test(true, bar, "Never");
new Class<int>().test(true, bar, "int"); new Class<int>().test(true, bar, "int");
new Class<bool>().test(false, bar, "bool"); new Class<bool>().test(false, bar, "bool");

View file

@ -69,6 +69,6 @@ main() {
new C<int>().test('int', false); new C<int>().test('int', false);
new C<dynamic>().test('dynamic', false); new C<dynamic>().test('dynamic', false);
new C<Object>().test('Object', false); new C<Object>().test('Object', false);
new C<Null>().test('Null', isWeakMode); new C<Null>().test('Null', hasUnsoundNullSafety);
new C<Never>().test('Null', true); new C<Never>().test('Null', true);
} }

View file

@ -41,7 +41,7 @@ class C<T> {
} }
main() { main() {
new C<bool>().test('bool', true, isWeakMode); new C<bool>().test('bool', true, hasUnsoundNullSafety);
new C<int>().test('int', false, false); new C<int>().test('int', false, false);
new C<dynamic>().test('dynamic', true, isWeakMode); new C<dynamic>().test('dynamic', true, hasUnsoundNullSafety);
} }

View file

@ -23,7 +23,7 @@ void test(var f, String constructorName) {
testDynamicTypeError(false, () => f(m1), "'new C.$constructorName(m1)'"); testDynamicTypeError(false, () => f(m1), "'new C.$constructorName(m1)'");
testDynamicTypeError(true, () => f(m2), "'new C.$constructorName(m2)'"); testDynamicTypeError(true, () => f(m2), "'new C.$constructorName(m2)'");
testDynamicTypeError( testDynamicTypeError(
isStrongMode, () => f(m3), "'new C.$constructorName(m3)'"); hasSoundNullSafety, () => f(m3), "'new C.$constructorName(m3)'");
testDynamicTypeError(true, () => f(m4), "'new C.$constructorName(m4)'"); testDynamicTypeError(true, () => f(m4), "'new C.$constructorName(m4)'");
testDynamicTypeError(false, () => f(m5), "'new C.$constructorName(m5)'"); testDynamicTypeError(false, () => f(m5), "'new C.$constructorName(m5)'");
} }

View file

@ -38,6 +38,6 @@ main() {
new C<int>().test('int', false); new C<int>().test('int', false);
new C<dynamic>().test('dynamic', false); new C<dynamic>().test('dynamic', false);
new C<Object>().test('Object', false); new C<Object>().test('Object', false);
new C<Null>().test('Null', isWeakMode); new C<Null>().test('Null', hasUnsoundNullSafety);
new C<Never>().test('Never', true); new C<Never>().test('Never', true);
} }

View file

@ -40,6 +40,6 @@ main() {
new D<bool, int>().test('int', false); new D<bool, int>().test('int', false);
new D<dynamic, dynamic>().test('dynamic', false); new D<dynamic, dynamic>().test('dynamic', false);
new D<Object, Object>().test('Object', false); new D<Object, Object>().test('Object', false);
new D<Null, Null>().test('Null', isWeakMode); new D<Null, Null>().test('Null', hasUnsoundNullSafety);
new D<Never, Never>().test('Never', true); new D<Never, Never>().test('Never', true);
} }

View file

@ -22,7 +22,7 @@ void bar(int i) {}
void main() { void main() {
new Class<dynamic>().test(true, bar, "dynamic"); new Class<dynamic>().test(true, bar, "dynamic");
new Class<Object>().test(true, bar, "Object"); new Class<Object>().test(true, bar, "Object");
new Class<Null>().test(isStrongMode, bar, "Null"); new Class<Null>().test(hasSoundNullSafety, bar, "Null");
new Class<Never>().test(false, bar, "Never"); new Class<Never>().test(false, bar, "Never");
new Class<int>().test(false, bar, "int"); new Class<int>().test(false, bar, "int");
new Class<bool>().test(true, bar, "bool"); new Class<bool>().test(true, bar, "bool");

View file

@ -26,7 +26,7 @@ void bar(int i) {}
void main() { void main() {
new Class<dynamic>().test(true, bar, "dynamic"); new Class<dynamic>().test(true, bar, "dynamic");
new Class<Object>().test(true, bar, "Object"); new Class<Object>().test(true, bar, "Object");
new Class<Null>().test(isStrongMode, bar, "Null"); new Class<Null>().test(hasSoundNullSafety, bar, "Null");
new Class<Never>().test(false, bar, "Never"); new Class<Never>().test(false, bar, "Never");
new Class<int>().test(false, bar, "int"); new Class<int>().test(false, bar, "int");
new Class<bool>().test(true, bar, "bool"); new Class<bool>().test(true, bar, "bool");

View file

@ -40,6 +40,6 @@ main() {
new C<int>().test('int', false); new C<int>().test('int', false);
new C<Object>().test('Object', false); new C<Object>().test('Object', false);
new C<dynamic>().test('dynamic', false); new C<dynamic>().test('dynamic', false);
new C<Null>().test('Null', isWeakMode); new C<Null>().test('Null', hasUnsoundNullSafety);
new C<Never>().test('Never', true); new C<Never>().test('Never', true);
} }

View file

@ -56,7 +56,7 @@ class GenericInstanceof {
} }
{ {
Foo foo = new Foo<List<Object>>(); Foo foo = new Foo<List<Object>>();
Expect.equals(isWeakMode, foo.isT(new List.filled(5, null))); Expect.equals(hasUnsoundNullSafety, foo.isT(new List.filled(5, null)));
Expect.equals(true, foo.isT(new List<Object>.filled(5, "o"))); Expect.equals(true, foo.isT(new List<Object>.filled(5, "o")));
Expect.equals(true, foo.isT(new List<int>.filled(5, 0))); Expect.equals(true, foo.isT(new List<int>.filled(5, 0)));
Expect.equals(true, foo.isT(new List<num>.filled(5, 0))); Expect.equals(true, foo.isT(new List<num>.filled(5, 0)));
@ -64,7 +64,7 @@ class GenericInstanceof {
} }
{ {
Foo foo = new Foo<List<int>>(); Foo foo = new Foo<List<int>>();
Expect.equals(isWeakMode, foo.isT(new List.filled(5, null))); Expect.equals(hasUnsoundNullSafety, foo.isT(new List.filled(5, null)));
Expect.equals(false, foo.isT(new List<Object>.filled(5, "o"))); Expect.equals(false, foo.isT(new List<Object>.filled(5, "o")));
Expect.equals(true, foo.isT(new List<int>.filled(5, 0))); Expect.equals(true, foo.isT(new List<int>.filled(5, 0)));
Expect.equals(false, foo.isT(new List<num>.filled(5, 0))); Expect.equals(false, foo.isT(new List<num>.filled(5, 0)));
@ -72,7 +72,7 @@ class GenericInstanceof {
} }
{ {
Foo foo = new Foo<List<num>>(); Foo foo = new Foo<List<num>>();
Expect.equals(isWeakMode, foo.isT(new List.filled(5, null))); Expect.equals(hasUnsoundNullSafety, foo.isT(new List.filled(5, null)));
Expect.equals(false, foo.isT(new List<Object>.filled(5, "o"))); Expect.equals(false, foo.isT(new List<Object>.filled(5, "o")));
Expect.equals(true, foo.isT(new List<int>.filled(5, 0))); Expect.equals(true, foo.isT(new List<int>.filled(5, 0)));
Expect.equals(true, foo.isT(new List<num>.filled(5, 0))); Expect.equals(true, foo.isT(new List<num>.filled(5, 0)));
@ -80,7 +80,7 @@ class GenericInstanceof {
} }
{ {
Foo foo = new Foo<List<String>>(); Foo foo = new Foo<List<String>>();
Expect.equals(isWeakMode, foo.isT(new List.filled(5, null))); Expect.equals(hasUnsoundNullSafety, foo.isT(new List.filled(5, null)));
Expect.equals(false, foo.isT(new List<Object>.filled(5, "o"))); Expect.equals(false, foo.isT(new List<Object>.filled(5, "o")));
Expect.equals(false, foo.isT(new List<int>.filled(5, 0))); Expect.equals(false, foo.isT(new List<int>.filled(5, 0)));
Expect.equals(false, foo.isT(new List<num>.filled(5, 0))); Expect.equals(false, foo.isT(new List<num>.filled(5, 0)));
@ -96,7 +96,8 @@ class GenericInstanceof {
} }
{ {
Foo foo = new Foo<Object>(); Foo foo = new Foo<Object>();
Expect.equals(isWeakMode, foo.isListT(new List.filled(5, null))); Expect.equals(
hasUnsoundNullSafety, foo.isListT(new List.filled(5, null)));
Expect.equals(true, foo.isListT(new List<Object>.filled(5, "o"))); Expect.equals(true, foo.isListT(new List<Object>.filled(5, "o")));
Expect.equals(true, foo.isListT(new List<int>.filled(5, 0))); Expect.equals(true, foo.isListT(new List<int>.filled(5, 0)));
Expect.equals(true, foo.isListT(new List<num>.filled(5, 0))); Expect.equals(true, foo.isListT(new List<num>.filled(5, 0)));
@ -104,7 +105,8 @@ class GenericInstanceof {
} }
{ {
Foo foo = new Foo<int>(); Foo foo = new Foo<int>();
Expect.equals(isWeakMode, foo.isListT(new List.filled(5, null))); Expect.equals(
hasUnsoundNullSafety, foo.isListT(new List.filled(5, null)));
Expect.equals(false, foo.isListT(new List<Object>.filled(5, "o"))); Expect.equals(false, foo.isListT(new List<Object>.filled(5, "o")));
Expect.equals(true, foo.isListT(new List<int>.filled(5, 0))); Expect.equals(true, foo.isListT(new List<int>.filled(5, 0)));
Expect.equals(false, foo.isListT(new List<num>.filled(5, 0))); Expect.equals(false, foo.isListT(new List<num>.filled(5, 0)));
@ -112,7 +114,8 @@ class GenericInstanceof {
} }
{ {
Foo foo = new Foo<num>(); Foo foo = new Foo<num>();
Expect.equals(isWeakMode, foo.isListT(new List.filled(5, null))); Expect.equals(
hasUnsoundNullSafety, foo.isListT(new List.filled(5, null)));
Expect.equals(false, foo.isListT(new List<Object>.filled(5, "o"))); Expect.equals(false, foo.isListT(new List<Object>.filled(5, "o")));
Expect.equals(true, foo.isListT(new List<int>.filled(5, 0))); Expect.equals(true, foo.isListT(new List<int>.filled(5, 0)));
Expect.equals(true, foo.isListT(new List<num>.filled(5, 0))); Expect.equals(true, foo.isListT(new List<num>.filled(5, 0)));
@ -120,7 +123,8 @@ class GenericInstanceof {
} }
{ {
Foo foo = new Foo<String>(); Foo foo = new Foo<String>();
Expect.equals(isWeakMode, foo.isListT(new List.filled(5, null))); Expect.equals(
hasUnsoundNullSafety, foo.isListT(new List.filled(5, null)));
Expect.equals(false, foo.isListT(new List<Object>.filled(5, "o"))); Expect.equals(false, foo.isListT(new List<Object>.filled(5, "o")));
Expect.equals(false, foo.isListT(new List<int>.filled(5, 0))); Expect.equals(false, foo.isListT(new List<int>.filled(5, 0)));
Expect.equals(false, foo.isListT(new List<num>.filled(5, 0))); Expect.equals(false, foo.isListT(new List<num>.filled(5, 0)));

View file

@ -38,6 +38,6 @@ main() {
Expect.isTrue(h is! Int2Int); Expect.isTrue(h is! Int2Int);
Expect.isTrue(h is! String2String); Expect.isTrue(h is! String2String);
Expect.equals(isWeakMode, h is Object2Object); Expect.equals(hasUnsoundNullSafety, h is Object2Object);
Expect.isTrue(h is! GenericMethod); Expect.isTrue(h is! GenericMethod);
} }

View file

@ -59,7 +59,7 @@ class InstanceofTest {
var a = new List.empty(); var a = new List.empty();
Expect.equals(true, a is List); Expect.equals(true, a is List);
Expect.equals(true, a is List<Object?>); Expect.equals(true, a is List<Object?>);
Expect.equals(isWeakMode, a is List<Object>); Expect.equals(hasUnsoundNullSafety, a is List<Object>);
Expect.equals(false, a is List<int>); Expect.equals(false, a is List<int>);
Expect.equals(false, a is List<num>); Expect.equals(false, a is List<num>);
Expect.equals(false, a is List<String>); Expect.equals(false, a is List<String>);

View file

@ -5,15 +5,15 @@
import 'package:expect/expect.dart'; import 'package:expect/expect.dart';
main() { main() {
const trueInWeakMode = <Null>[] is List<int>; const trueInNoSoundMode = <Null>[] is List<int>;
Expect.equals(isWeakMode, trueInWeakMode); Expect.equals(hasUnsoundNullSafety, trueInNoSoundMode);
// The following tests use the Uri.pathSegments() to access a constant list // The following tests use the Uri.pathSegments() to access a constant list
// that is defined in the SDK and verify the type associated with it does not // that is defined in the SDK and verify the type associated with it does not
// allow null when running with sound null safety. // allow null when running with sound null safety.
var emptyUri = Uri(pathSegments: []); var emptyUri = Uri(pathSegments: []);
dynamic stringList = emptyUri.pathSegments.toList(); dynamic stringList = emptyUri.pathSegments.toList();
if (isStrongMode) { if (hasSoundNullSafety) {
Expect.throwsTypeError(() { Expect.throwsTypeError(() {
stringList.add(null); stringList.add(null);
}); });

View file

@ -145,13 +145,13 @@ void test() {
// Test cast, "as", operator. // Test cast, "as", operator.
Expect.equals(null, null as Null); Expect.equals(null, null as Null);
if (isStrongMode) { if (hasSoundNullSafety) {
Expect.throwsTypeError(() => null as Object); Expect.throwsTypeError(() => null as Object);
} else { } else {
Expect.equals(null, null as Object); Expect.equals(null, null as Object);
} }
Expect.equals(null, null as Object?); Expect.equals(null, null as Object?);
if (isStrongMode) { if (hasSoundNullSafety) {
Expect.throwsTypeError(() => null as int); Expect.throwsTypeError(() => null as int);
} else { } else {
Expect.equals(null, null as int); Expect.equals(null, null as int);
@ -163,13 +163,13 @@ void test() {
Expect.equals(null, new Generic<int?>().cast(null)); Expect.equals(null, new Generic<int?>().cast(null));
Expect.equals(null, obj as Null); Expect.equals(null, obj as Null);
if (isStrongMode) { if (hasSoundNullSafety) {
Expect.throwsTypeError(() => obj as Object); Expect.throwsTypeError(() => obj as Object);
} else { } else {
Expect.equals(null, obj as Object); Expect.equals(null, obj as Object);
} }
Expect.equals(null, obj as Object?); Expect.equals(null, obj as Object?);
if (isStrongMode) { if (hasSoundNullSafety) {
Expect.throwsTypeError(() => obj as int); Expect.throwsTypeError(() => obj as int);
} else { } else {
Expect.equals(null, obj as int); Expect.equals(null, obj as int);

View file

@ -16,7 +16,7 @@ void main() {
} }
void expectError(Function() callback) { void expectError(Function() callback) {
if (isWeakMode) { if (hasUnsoundNullSafety) {
Expect.throwsAssertionError(callback); Expect.throwsAssertionError(callback);
} else { } else {
Expect.throwsTypeError(callback); Expect.throwsTypeError(callback);

View file

@ -43,8 +43,8 @@ void test() {
var item = items[i]; var item = items[i];
String code = answers[i]; String code = answers[i];
bool expected = code == 'T' || bool expected = code == 'T' ||
(code == 'S' && isStrongMode) || (code == 'S' && hasSoundNullSafety) ||
(code == 'W' && isWeakMode); (code == 'W' && hasUnsoundNullSafety);
Expect.equals(expected, predicate(item), "$predicate '$code' $item"); Expect.equals(expected, predicate(item), "$predicate '$code' $item");
} }
} }

View file

@ -81,7 +81,7 @@ void testStackTrace(void testCase(dynamic condition), List<int> lineNumbers) {
print(stacktrace); print(stacktrace);
print('-----------------------------'); print('-----------------------------');
if (isStrongMode) { if (hasSoundNullSafety) {
Expect.isTrue(e is TypeError); Expect.isTrue(e is TypeError);
Expect.equals( Expect.equals(
"type 'Null' is not a subtype of type 'bool'", e.toString()); "type 'Null' is not a subtype of type 'bool'", e.toString());

View file

@ -18,7 +18,7 @@ void test() {
InstanceMirror im1 = reflect(null); InstanceMirror im1 = reflect(null);
Expect.equals(cm, im1.type); Expect.equals(cm, im1.type);
if (isStrongMode) { if (hasSoundNullSafety) {
Expect.throwsTypeError(() => im1.invoke(const Symbol("=="), [null]), Expect.throwsTypeError(() => im1.invoke(const Symbol("=="), [null]),
'null not assignable to Object'); 'null not assignable to Object');
} else { } else {
@ -29,7 +29,7 @@ void test() {
var obj = confuse(null); // Null value that isn't known at compile-time. var obj = confuse(null); // Null value that isn't known at compile-time.
InstanceMirror im2 = reflect(obj); InstanceMirror im2 = reflect(obj);
Expect.equals(cm, im2.type); Expect.equals(cm, im2.type);
if (isStrongMode) { if (hasSoundNullSafety) {
Expect.throwsTypeError(() => im2.invoke(const Symbol("=="), [null]), Expect.throwsTypeError(() => im2.invoke(const Symbol("=="), [null]),
'null not assignable to Object'); 'null not assignable to Object');
} else { } else {
@ -41,7 +41,7 @@ void test() {
Expect.isTrue(nullMirror.getField(#hashCode).reflectee is int); Expect.isTrue(nullMirror.getField(#hashCode).reflectee is int);
Expect.equals(null.hashCode, nullMirror.getField(#hashCode).reflectee); Expect.equals(null.hashCode, nullMirror.getField(#hashCode).reflectee);
Expect.equals('Null', nullMirror.getField(#runtimeType).reflectee.toString()); Expect.equals('Null', nullMirror.getField(#runtimeType).reflectee.toString());
if (isStrongMode) { if (hasSoundNullSafety) {
Expect.throwsTypeError( Expect.throwsTypeError(
() => nullMirror.invoke(#==, [null]), 'null not assignable to Object'); () => nullMirror.invoke(#==, [null]), 'null not assignable to Object');
} else { } else {