Skip to content

Commit 79ecc59

Browse files
committed
#3057. Operator == tests renamed and fixed
1 parent 5198824 commit 79ecc59

13 files changed

+221
-215
lines changed

TypeSystem/flow-analysis/reachability_A01_t04.dart

Lines changed: 0 additions & 32 deletions
This file was deleted.

TypeSystem/flow-analysis/reachability_A01_t06.dart

Lines changed: 0 additions & 33 deletions
This file was deleted.

TypeSystem/flow-analysis/reachability_A01_t07.dart

Lines changed: 0 additions & 34 deletions
This file was deleted.

TypeSystem/flow-analysis/reachability_A01_t08.dart

Lines changed: 0 additions & 40 deletions
This file was deleted.

TypeSystem/flow-analysis/reachability_A01_t10.dart

Lines changed: 0 additions & 41 deletions
This file was deleted.
Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
// Copyright (c) 2020, the Dart project authors. Please see the AUTHORS file
2+
// for details. All rights reserved. Use of this source code is governed by a
3+
// BSD-style license that can be found in the LICENSE file.
4+
5+
/// @assertion operator== If `N` is an expression of the form `E1 == E2`, where
6+
/// the static type of `E1` is `T1` and the static type of `E2` is `T2`, then:
7+
/// - Let `before(E1) = before(N)`.
8+
/// - Let `before(E2) = after(E1)`.
9+
/// - If `equivalentToNull(T1)` and `equivalentToNull(T2)`, then:
10+
/// - Let `true(N) = after(E2)`.
11+
/// - Let `false(N) = unreachable(after(E2))`.
12+
/// - Otherwise, if `equivalentToNull(T1)` and `T2` is non-nullable, or
13+
/// `equivalentToNull(T2)` and `T1` is non-nullable, then:
14+
/// - Let `true(N) = unreachable(after(E2))`.
15+
/// - Let `false(N) = after(E2)`.
16+
/// - Otherwise, if `stripParens(E1)` is a `null` literal, then:
17+
/// - Let `true(N) = after(E2)`.
18+
/// - Let `false(N) = promoteToNonNull(E2, after(E2))`.
19+
/// - Otherwise, if `stripParens(E2)` is a `null` literal, then:
20+
/// - Let `true(N) = after(E1)`.
21+
/// - Let `false(N) = promoteToNonNull(E1, after(E2))`.
22+
/// - Otherwise:
23+
/// - Let after(N) = after(E2).
24+
/// Note that it is tempting to generalize the two `null` literal cases to apply
25+
/// to any expression whose type is `Null`, but this would be unsound in cases
26+
/// where `E2` assigns to `x`. (Consider, for example,
27+
/// `(int? x) => x == (x = null) ? true : x.isEven`, which tries to call
28+
/// `null.isEven` in the event of a non-null input).
29+
///
30+
/// @description Checks that if `equivalentToNull(T1)` and
31+
/// `equivalentToNull(T2)`, then `true(N) = after(E2)` and
32+
/// `false(N) = unreachable(after(E2))`.
33+
/// @author [email protected]
34+
/// @issue 41985
35+
36+
// Requirements=nnbd-strong
37+
38+
main() {
39+
int i;
40+
Null n = null;
41+
if (n == null) {
42+
i = 42; // condition is always true therefore `i` must be definitely assigned
43+
}
44+
i; // It's not an error to read local non-nullable variable if it is definitely assigned
45+
}
Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
// Copyright (c) 2020, the Dart project authors. Please see the AUTHORS file
2+
// for details. All rights reserved. Use of this source code is governed by a
3+
// BSD-style license that can be found in the LICENSE file.
4+
5+
/// @assertion operator== If `N` is an expression of the form `E1 == E2`, where
6+
/// the static type of `E1` is `T1` and the static type of `E2` is `T2`, then:
7+
/// - Let `before(E1) = before(N)`.
8+
/// - Let `before(E2) = after(E1)`.
9+
/// - If `equivalentToNull(T1)` and `equivalentToNull(T2)`, then:
10+
/// - Let `true(N) = after(E2)`.
11+
/// - Let `false(N) = unreachable(after(E2))`.
12+
/// - Otherwise, if `equivalentToNull(T1)` and `T2` is non-nullable, or
13+
/// `equivalentToNull(T2)` and `T1` is non-nullable, then:
14+
/// - Let `true(N) = unreachable(after(E2))`.
15+
/// - Let `false(N) = after(E2)`.
16+
/// - Otherwise, if `stripParens(E1)` is a `null` literal, then:
17+
/// - Let `true(N) = after(E2)`.
18+
/// - Let `false(N) = promoteToNonNull(E2, after(E2))`.
19+
/// - Otherwise, if `stripParens(E2)` is a `null` literal, then:
20+
/// - Let `true(N) = after(E1)`.
21+
/// - Let `false(N) = promoteToNonNull(E1, after(E2))`.
22+
/// - Otherwise:
23+
/// - Let after(N) = after(E2).
24+
/// Note that it is tempting to generalize the two `null` literal cases to apply
25+
/// to any expression whose type is `Null`, but this would be unsound in cases
26+
/// where `E2` assigns to `x`. (Consider, for example,
27+
/// `(int? x) => x == (x = null) ? true : x.isEven`, which tries to call
28+
/// `null.isEven` in the event of a non-null input).
29+
///
30+
/// @description Checks that if `equivalentToNull(T1)` and
31+
/// `equivalentToNull(T2)`, then `true(N) = after(E2)` and
32+
/// `false(N) = unreachable(after(E2))`. Test getter of type `Null`.
33+
/// @author [email protected]
34+
/// @issue 41985
35+
36+
// Requirements=nnbd-strong
37+
38+
Null get n => null;
39+
40+
main() {
41+
int i;
42+
if (n == null) {
43+
i = 42; // condition is always true therefore `i` must be definitely assigned
44+
}
45+
i; // It's not an error to read local non-nullable variable if it is definitely assigned
46+
}
Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
// Copyright (c) 2020, the Dart project authors. Please see the AUTHORS file
2+
// for details. All rights reserved. Use of this source code is governed by a
3+
// BSD-style license that can be found in the LICENSE file.
4+
5+
/// @assertion operator== If `N` is an expression of the form `E1 == E2`, where
6+
/// the static type of `E1` is `T1` and the static type of `E2` is `T2`, then:
7+
/// - Let `before(E1) = before(N)`.
8+
/// - Let `before(E2) = after(E1)`.
9+
/// - If `equivalentToNull(T1)` and `equivalentToNull(T2)`, then:
10+
/// - Let `true(N) = after(E2)`.
11+
/// - Let `false(N) = unreachable(after(E2))`.
12+
/// - Otherwise, if `equivalentToNull(T1)` and `T2` is non-nullable, or
13+
/// `equivalentToNull(T2)` and `T1` is non-nullable, then:
14+
/// - Let `true(N) = unreachable(after(E2))`.
15+
/// - Let `false(N) = after(E2)`.
16+
/// - Otherwise, if `stripParens(E1)` is a `null` literal, then:
17+
/// - Let `true(N) = after(E2)`.
18+
/// - Let `false(N) = promoteToNonNull(E2, after(E2))`.
19+
/// - Otherwise, if `stripParens(E2)` is a `null` literal, then:
20+
/// - Let `true(N) = after(E1)`.
21+
/// - Let `false(N) = promoteToNonNull(E1, after(E2))`.
22+
/// - Otherwise:
23+
/// - Let after(N) = after(E2).
24+
/// Note that it is tempting to generalize the two `null` literal cases to apply
25+
/// to any expression whose type is `Null`, but this would be unsound in cases
26+
/// where `E2` assigns to `x`. (Consider, for example,
27+
/// `(int? x) => x == (x = null) ? true : x.isEven`, which tries to call
28+
/// `null.isEven` in the event of a non-null input).
29+
///
30+
/// @description Checks reachability after variable or getter. Test non-nullable
31+
/// type.
32+
/// @author [email protected]
33+
/// @issue 41981
34+
/// @issue 60114
35+
36+
// Requirements=nnbd-strong
37+
38+
main() {
39+
late int i;
40+
String s = "";
41+
if (s == null) { // ignore: unnecessary_null_comparison
42+
i = 42; // `i` is definitely unassigned
43+
}
44+
i;
45+
//^
46+
// [analyzer] unspecified
47+
// [cfe] unspecified
48+
}
Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
// Copyright (c) 2020, the Dart project authors. Please see the AUTHORS file
2+
// for details. All rights reserved. Use of this source code is governed by a
3+
// BSD-style license that can be found in the LICENSE file.
4+
5+
/// @assertion operator== If `N` is an expression of the form `E1 == E2`, where
6+
/// the static type of `E1` is `T1` and the static type of `E2` is `T2`, then:
7+
/// - Let `before(E1) = before(N)`.
8+
/// - Let `before(E2) = after(E1)`.
9+
/// - If `equivalentToNull(T1)` and `equivalentToNull(T2)`, then:
10+
/// - Let `true(N) = after(E2)`.
11+
/// - Let `false(N) = unreachable(after(E2))`.
12+
/// - Otherwise, if `equivalentToNull(T1)` and `T2` is non-nullable, or
13+
/// `equivalentToNull(T2)` and `T1` is non-nullable, then:
14+
/// - Let `true(N) = unreachable(after(E2))`.
15+
/// - Let `false(N) = after(E2)`.
16+
/// - Otherwise, if `stripParens(E1)` is a `null` literal, then:
17+
/// - Let `true(N) = after(E2)`.
18+
/// - Let `false(N) = promoteToNonNull(E2, after(E2))`.
19+
/// - Otherwise, if `stripParens(E2)` is a `null` literal, then:
20+
/// - Let `true(N) = after(E1)`.
21+
/// - Let `false(N) = promoteToNonNull(E1, after(E2))`.
22+
/// - Otherwise:
23+
/// - Let after(N) = after(E2).
24+
/// Note that it is tempting to generalize the two `null` literal cases to apply
25+
/// to any expression whose type is `Null`, but this would be unsound in cases
26+
/// where `E2` assigns to `x`. (Consider, for example,
27+
/// `(int? x) => x == (x = null) ? true : x.isEven`, which tries to call
28+
/// `null.isEven` in the event of a non-null input).
29+
///
30+
/// @description Checks reachability after variable or getter. Test getter of
31+
/// non-nullable type
32+
/// @author [email protected]
33+
/// @issue 41981
34+
/// @issue 60114
35+
36+
// Requirements=nnbd-strong
37+
38+
String get s => "Lily was here";
39+
40+
main() {
41+
late int i;
42+
if (s == null) { // ignore: unnecessary_null_comparison
43+
i = 42; // `i` is definitely unassigned
44+
}
45+
i;
46+
//^
47+
// [analyzer] unspecified
48+
// [cfe] unspecified
49+
}

0 commit comments

Comments
 (0)