#460. Fix null-promotion tests
diff --git a/LanguageFeatures/nnbd/Null_promotion_A01_t01.dart b/LanguageFeatures/nnbd/Null_promotion_A01_t01.dart
index 59273e0..c231aa2 100644
--- a/LanguageFeatures/nnbd/Null_promotion_A01_t01.dart
+++ b/LanguageFeatures/nnbd/Null_promotion_A01_t01.dart
@@ -9,51 +9,52 @@
* continuation, and to [NonNull(T)] in the [false] continuation.
*
* @description Check that [e] is promoted to [Null] in the [true] condition.
+ * Test [e == null] expression
* @author iarkh@unipro.ru
+ * @author sgrekhov@unipro.ru
*/
-// SharedOptions=--enable-experiment=non-nullable,nonfunction-type-aliases
+// SharedOptions=--enable-experiment=non-nullable
-import "../../Utils/expect.dart";
-
-class A {}
-class B<T> {}
-
-typedef AA = A;
-typedef AAA = A?;
-
-void checkme(var x, var expectedType) {
- Expect.equals(Null, x.runtimeType);
- Expect.isTrue(x == null);
- Expect.isTrue(x is Null);
- Expect.isFalse(x is NonNull(expectedType));
+class A {
+ foo() {}
}
+class B<T> {
+ bar() {}
+}
+
+dynamic init() => null;
+
main() {
- checkme(null, Null);
+ A? a = init();
+ if (a == null) {
+ a.foo();
+// ^^^
+// [analyzer] unspecified
+// [cfe] unspecified
+ }
- A ? a = null;
- checkme(a, A);
+ B? b1 = init();
+ if (b1 == null) {
+ b1.bar();
+// ^^^
+// [analyzer] unspecified
+// [cfe] unspecified
+ }
- B? b1 = null;
- checkme(b1, B);
+ B<int>? b2 = init();
+ if (b2 == null) {
+ b2.bar();
+// ^^^
+// [analyzer] unspecified
+// [cfe] unspecified
+ }
- B<int> ? b2 = null;
- checkme(b2, B);
-
- dynamic ? d = null;
- checkme(d, dynamic);
-
- Object ? o = null;
- checkme(o, Object);
-
- Null n = null;
- checkme(n, Null);
-
- AA ? aa = null;
- checkme(aa, AA);
- checkme(aa, A);
-
- AAA aaa = null;
- checkme(aaa, AAA);
- checkme(aaa, A);
+ int? i = init();
+ if (i == null) {
+ i.isOdd;
+// ^^^^^
+// [analyzer] unspecified
+// [cfe] unspecified
+ }
}
diff --git a/LanguageFeatures/nnbd/Null_promotion_A01_t02.dart b/LanguageFeatures/nnbd/Null_promotion_A01_t02.dart
index b8a48b2..4d8bbe9 100644
--- a/LanguageFeatures/nnbd/Null_promotion_A01_t02.dart
+++ b/LanguageFeatures/nnbd/Null_promotion_A01_t02.dart
@@ -8,50 +8,52 @@
* [e] has static type [T] promotes the type of [e] to [Null] in the [true]
* continuation, and to [NonNull(T)] in the [false] continuation.
*
- * @description Check that [e] is promoted to [NonNull(T)] in the [false]
- * condition.
- * @author iarkh@unipro.ru
+ * @description Check that [e] is promoted to [Null] in the [true] condition.
+ * Test [e is Null] expression
+ * @author sgrekhov@unipro.ru
*/
-// SharedOptions=--enable-experiment=non-nullable,nonfunction-type-aliases
+// SharedOptions=--enable-experiment=non-nullable
-import "../../Utils/expect.dart";
-
-class A {}
-class B<T> {}
-
-typedef AA = A;
-typedef AAA = A?;
-
-void checkme(var x, var expectedType) {
- Expect.isFalse(x == null);
- Expect.isFalse(x is Null);
- Expect.isTrue(x is NonNull(expectedType));
- Expect.isTrue(x is NonNull(Object));
+class A {
+ foo() {}
}
+class B<T> {
+ bar() {}
+}
+
+dynamic init() => null;
+
main() {
- A a1 = A();
- checkme(a1, A);
+ A? a = init();
+ if (a is Null) {
+ a.foo();
+// ^^^
+// [analyzer] unspecified
+// [cfe] unspecified
+ }
- A? a2 = A();
- checkme(a2, A);
+ B? b1 = init();
+ if (b1 is null) {
+ b1.bar();
+// ^^^
+// [analyzer] unspecified
+// [cfe] unspecified
+ }
- B b1 = B();
- checkme(b1, B);
+ B<int>? b2 = init();
+ if (b2 is Null) {
+ b2.bar();
+// ^^^
+// [analyzer] unspecified
+// [cfe] unspecified
+ }
- B? b2 = B();
- checkme(b2, B);
-
- B<int> b3 = B<int>();
- checkme(b3, B);
-
- B<int> ? b4 = B<int>();
- checkme(b4, B);
-
- dynamic d = 12345;
- checkme(d, int);
- checkme(d, dynamic);
-
- Object o = "14";
- checkme(o, String);
+ int? i = init();
+ if (i is Null) {
+ i.isOdd;
+// ^^^^^
+// [analyzer] unspecified
+// [cfe] unspecified
+ }
}
diff --git a/LanguageFeatures/nnbd/Null_promotion_A01_t03.dart b/LanguageFeatures/nnbd/Null_promotion_A01_t03.dart
new file mode 100644
index 0000000..cda52f2
--- /dev/null
+++ b/LanguageFeatures/nnbd/Null_promotion_A01_t03.dart
@@ -0,0 +1,56 @@
+/*
+ * 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.
+ */
+/**
+ * @assertion A check of the form [e == null] or of the form [e is Null] where
+ * [e] has static type [T] promotes the type of [e] to [Null] in the [true]
+ * continuation, and to [NonNull(T)] in the [false] continuation.
+ *
+ * @description Check that [e] is promoted to [Null] in the [true] condition.
+ * Test type aliases
+ * @author sgrekhov@unipro.ru
+ */
+// SharedOptions=--enable-experiment=non-nullable,nonfunction-type-aliases
+
+class A {
+ foo() {}
+}
+
+typedef AAlias1 = A?
+typedef AAlias2 = AAlias1?
+
+dynamic init() => null;
+
+main() {
+ AAlias1 a1 = init();
+ if (a1 is Null) {
+ a1.foo();
+// ^^^
+// [analyzer] unspecified
+// [cfe] unspecified
+ }
+
+ if (a1 == null) {
+ a1.foo();
+// ^^^
+// [analyzer] unspecified
+// [cfe] unspecified
+ }
+
+ AAlias2? a2 = init();
+ if (a2 is Null) {
+ a2.foo();
+// ^^^
+// [analyzer] unspecified
+// [cfe] unspecified
+ }
+
+ if (a2 == null) {
+ a2.foo();
+// ^^^
+// [analyzer] unspecified
+// [cfe] unspecified
+ }
+}
diff --git a/LanguageFeatures/nnbd/Null_promotion_A01_t04.dart b/LanguageFeatures/nnbd/Null_promotion_A01_t04.dart
new file mode 100644
index 0000000..daa752b
--- /dev/null
+++ b/LanguageFeatures/nnbd/Null_promotion_A01_t04.dart
@@ -0,0 +1,35 @@
+/*
+ * 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.
+ */
+/**
+ * @assertion A check of the form [e == null] or of the form [e is Null] where
+ * [e] has static type [T] promotes the type of [e] to [Null] in the [true]
+ * continuation, and to [NonNull(T)] in the [false] continuation.
+ *
+ * @description Check that [e] is promoted to [Null] in the [true] condition.
+ * Test pre-NNBD legacy types
+ * @author sgrekhov@unipro.ru
+ */
+// SharedOptions=--enable-experiment=non-nullable
+import "legacy_library_lib.dart";
+
+dynamic init() => null;
+
+main() {
+ A a = init();
+ if (a is Null) {
+ a.foo();
+// ^^^
+// [analyzer] unspecified
+// [cfe] unspecified
+ }
+
+ if (a == null) {
+ a.foo();
+// ^^^
+// [analyzer] unspecified
+// [cfe] unspecified
+ }
+}
diff --git a/LanguageFeatures/nnbd/Null_promotion_A01_t05.dart b/LanguageFeatures/nnbd/Null_promotion_A01_t05.dart
new file mode 100644
index 0000000..d020f99
--- /dev/null
+++ b/LanguageFeatures/nnbd/Null_promotion_A01_t05.dart
@@ -0,0 +1,53 @@
+/*
+ * 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.
+ */
+/**
+ * @assertion A check of the form [e == null] or of the form [e is Null] where
+ * [e] has static type [T] promotes the type of [e] to [Null] in the [true]
+ * continuation, and to [NonNull(T)] in the [false] continuation.
+ *
+ * @description Check that [e] is promoted to [Null] in the [true] condition.
+ * Test pre-NNBD legacy types and type aliases
+ * @author sgrekhov@unipro.ru
+ */
+// SharedOptions=--enable-experiment=non-nullable,nonfunction-type-aliases
+import "legacy_library_lib.dart";
+import "legacy_library_aliases_lib.dart" as legacy;
+
+dynamic init() => null;
+
+typedef AAlias = A;
+
+main() {
+ AAlias a1 = init();
+ if (a1 is Null) {
+ a1.foo();
+// ^^^
+// [analyzer] unspecified
+// [cfe] unspecified
+ }
+
+ if (a1 == null) {
+ a1.foo();
+// ^^^
+// [analyzer] unspecified
+// [cfe] unspecified
+ }
+
+ legacy.AAlias a2 = init();
+ if (a2 is Null) {
+ a2.bar();
+// ^^^
+// [analyzer] unspecified
+// [cfe] unspecified
+ }
+
+ if (a2 == null) {
+ a2.bar();
+// ^^^
+// [analyzer] unspecified
+// [cfe] unspecified
+ }
+}
diff --git a/LanguageFeatures/nnbd/legacy_library_aliases_lib.dart b/LanguageFeatures/nnbd/legacy_library_aliases_lib.dart
index 51f66e3..b5edb3c 100644
--- a/LanguageFeatures/nnbd/legacy_library_aliases_lib.dart
+++ b/LanguageFeatures/nnbd/legacy_library_aliases_lib.dart
@@ -11,6 +11,7 @@
library legacy_library_aliases_lib;
class A {
+ void bar() {}
}
typedef AAlias = A;
diff --git a/LanguageFeatures/nnbd/legacy_library_lib.dart b/LanguageFeatures/nnbd/legacy_library_lib.dart
index eb80704..3b6a5ee 100644
--- a/LanguageFeatures/nnbd/legacy_library_lib.dart
+++ b/LanguageFeatures/nnbd/legacy_library_lib.dart
@@ -11,6 +11,7 @@
library legacy_library_lib;
class A {
+ void foo() {}
}
class C<X extends A> {