Skip to content

Commit

Permalink
dart-lang#3057. Operator == tests renamed and fixed
Browse files Browse the repository at this point in the history
  • Loading branch information
sgrekhov committed Feb 12, 2025
1 parent 5198824 commit 79ecc59
Show file tree
Hide file tree
Showing 13 changed files with 221 additions and 215 deletions.
32 changes: 0 additions & 32 deletions TypeSystem/flow-analysis/reachability_A01_t04.dart

This file was deleted.

33 changes: 0 additions & 33 deletions TypeSystem/flow-analysis/reachability_A01_t06.dart

This file was deleted.

34 changes: 0 additions & 34 deletions TypeSystem/flow-analysis/reachability_A01_t07.dart

This file was deleted.

40 changes: 0 additions & 40 deletions TypeSystem/flow-analysis/reachability_A01_t08.dart

This file was deleted.

41 changes: 0 additions & 41 deletions TypeSystem/flow-analysis/reachability_A01_t10.dart

This file was deleted.

45 changes: 45 additions & 0 deletions TypeSystem/flow-analysis/reachability_A08_t01.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
// 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.

/// @assertion operator== If `N` is an expression of the form `E1 == E2`, where
/// the static type of `E1` is `T1` and the static type of `E2` is `T2`, then:
/// - Let `before(E1) = before(N)`.
/// - Let `before(E2) = after(E1)`.
/// - If `equivalentToNull(T1)` and `equivalentToNull(T2)`, then:
/// - Let `true(N) = after(E2)`.
/// - Let `false(N) = unreachable(after(E2))`.
/// - Otherwise, if `equivalentToNull(T1)` and `T2` is non-nullable, or
/// `equivalentToNull(T2)` and `T1` is non-nullable, then:
/// - Let `true(N) = unreachable(after(E2))`.
/// - Let `false(N) = after(E2)`.
/// - Otherwise, if `stripParens(E1)` is a `null` literal, then:
/// - Let `true(N) = after(E2)`.
/// - Let `false(N) = promoteToNonNull(E2, after(E2))`.
/// - Otherwise, if `stripParens(E2)` is a `null` literal, then:
/// - Let `true(N) = after(E1)`.
/// - Let `false(N) = promoteToNonNull(E1, after(E2))`.
/// - Otherwise:
/// - Let after(N) = after(E2).
/// Note that it is tempting to generalize the two `null` literal cases to apply
/// to any expression whose type is `Null`, but this would be unsound in cases
/// where `E2` assigns to `x`. (Consider, for example,
/// `(int? x) => x == (x = null) ? true : x.isEven`, which tries to call
/// `null.isEven` in the event of a non-null input).
///
/// @description Checks that if `equivalentToNull(T1)` and
/// `equivalentToNull(T2)`, then `true(N) = after(E2)` and
/// `false(N) = unreachable(after(E2))`.
/// @author [email protected]
/// @issue 41985
// Requirements=nnbd-strong

main() {
int i;
Null n = null;
if (n == null) {
i = 42; // condition is always true therefore `i` must be definitely assigned
}
i; // It's not an error to read local non-nullable variable if it is definitely assigned
}
46 changes: 46 additions & 0 deletions TypeSystem/flow-analysis/reachability_A08_t02.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
// 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.

/// @assertion operator== If `N` is an expression of the form `E1 == E2`, where
/// the static type of `E1` is `T1` and the static type of `E2` is `T2`, then:
/// - Let `before(E1) = before(N)`.
/// - Let `before(E2) = after(E1)`.
/// - If `equivalentToNull(T1)` and `equivalentToNull(T2)`, then:
/// - Let `true(N) = after(E2)`.
/// - Let `false(N) = unreachable(after(E2))`.
/// - Otherwise, if `equivalentToNull(T1)` and `T2` is non-nullable, or
/// `equivalentToNull(T2)` and `T1` is non-nullable, then:
/// - Let `true(N) = unreachable(after(E2))`.
/// - Let `false(N) = after(E2)`.
/// - Otherwise, if `stripParens(E1)` is a `null` literal, then:
/// - Let `true(N) = after(E2)`.
/// - Let `false(N) = promoteToNonNull(E2, after(E2))`.
/// - Otherwise, if `stripParens(E2)` is a `null` literal, then:
/// - Let `true(N) = after(E1)`.
/// - Let `false(N) = promoteToNonNull(E1, after(E2))`.
/// - Otherwise:
/// - Let after(N) = after(E2).
/// Note that it is tempting to generalize the two `null` literal cases to apply
/// to any expression whose type is `Null`, but this would be unsound in cases
/// where `E2` assigns to `x`. (Consider, for example,
/// `(int? x) => x == (x = null) ? true : x.isEven`, which tries to call
/// `null.isEven` in the event of a non-null input).
///
/// @description Checks that if `equivalentToNull(T1)` and
/// `equivalentToNull(T2)`, then `true(N) = after(E2)` and
/// `false(N) = unreachable(after(E2))`. Test getter of type `Null`.
/// @author [email protected]
/// @issue 41985
// Requirements=nnbd-strong

Null get n => null;

main() {
int i;
if (n == null) {
i = 42; // condition is always true therefore `i` must be definitely assigned
}
i; // It's not an error to read local non-nullable variable if it is definitely assigned
}
48 changes: 48 additions & 0 deletions TypeSystem/flow-analysis/reachability_A08_t03.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
// 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.

/// @assertion operator== If `N` is an expression of the form `E1 == E2`, where
/// the static type of `E1` is `T1` and the static type of `E2` is `T2`, then:
/// - Let `before(E1) = before(N)`.
/// - Let `before(E2) = after(E1)`.
/// - If `equivalentToNull(T1)` and `equivalentToNull(T2)`, then:
/// - Let `true(N) = after(E2)`.
/// - Let `false(N) = unreachable(after(E2))`.
/// - Otherwise, if `equivalentToNull(T1)` and `T2` is non-nullable, or
/// `equivalentToNull(T2)` and `T1` is non-nullable, then:
/// - Let `true(N) = unreachable(after(E2))`.
/// - Let `false(N) = after(E2)`.
/// - Otherwise, if `stripParens(E1)` is a `null` literal, then:
/// - Let `true(N) = after(E2)`.
/// - Let `false(N) = promoteToNonNull(E2, after(E2))`.
/// - Otherwise, if `stripParens(E2)` is a `null` literal, then:
/// - Let `true(N) = after(E1)`.
/// - Let `false(N) = promoteToNonNull(E1, after(E2))`.
/// - Otherwise:
/// - Let after(N) = after(E2).
/// Note that it is tempting to generalize the two `null` literal cases to apply
/// to any expression whose type is `Null`, but this would be unsound in cases
/// where `E2` assigns to `x`. (Consider, for example,
/// `(int? x) => x == (x = null) ? true : x.isEven`, which tries to call
/// `null.isEven` in the event of a non-null input).
///
/// @description Checks reachability after variable or getter. Test non-nullable
/// type.
/// @author [email protected]
/// @issue 41981
/// @issue 60114
// Requirements=nnbd-strong

main() {
late int i;
String s = "";
if (s == null) { // ignore: unnecessary_null_comparison
i = 42; // `i` is definitely unassigned
}
i;
//^
// [analyzer] unspecified
// [cfe] unspecified
}
49 changes: 49 additions & 0 deletions TypeSystem/flow-analysis/reachability_A08_t04.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
// 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.

/// @assertion operator== If `N` is an expression of the form `E1 == E2`, where
/// the static type of `E1` is `T1` and the static type of `E2` is `T2`, then:
/// - Let `before(E1) = before(N)`.
/// - Let `before(E2) = after(E1)`.
/// - If `equivalentToNull(T1)` and `equivalentToNull(T2)`, then:
/// - Let `true(N) = after(E2)`.
/// - Let `false(N) = unreachable(after(E2))`.
/// - Otherwise, if `equivalentToNull(T1)` and `T2` is non-nullable, or
/// `equivalentToNull(T2)` and `T1` is non-nullable, then:
/// - Let `true(N) = unreachable(after(E2))`.
/// - Let `false(N) = after(E2)`.
/// - Otherwise, if `stripParens(E1)` is a `null` literal, then:
/// - Let `true(N) = after(E2)`.
/// - Let `false(N) = promoteToNonNull(E2, after(E2))`.
/// - Otherwise, if `stripParens(E2)` is a `null` literal, then:
/// - Let `true(N) = after(E1)`.
/// - Let `false(N) = promoteToNonNull(E1, after(E2))`.
/// - Otherwise:
/// - Let after(N) = after(E2).
/// Note that it is tempting to generalize the two `null` literal cases to apply
/// to any expression whose type is `Null`, but this would be unsound in cases
/// where `E2` assigns to `x`. (Consider, for example,
/// `(int? x) => x == (x = null) ? true : x.isEven`, which tries to call
/// `null.isEven` in the event of a non-null input).
///
/// @description Checks reachability after variable or getter. Test getter of
/// non-nullable type
/// @author [email protected]
/// @issue 41981
/// @issue 60114
// Requirements=nnbd-strong

String get s => "Lily was here";

main() {
late int i;
if (s == null) { // ignore: unnecessary_null_comparison
i = 42; // `i` is definitely unassigned
}
i;
//^
// [analyzer] unspecified
// [cfe] unspecified
}
Loading

0 comments on commit 79ecc59

Please sign in to comment.