forked from dart-lang/co19
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
dart-lang#3057. Operator
==
tests renamed and fixed
- Loading branch information
Showing
13 changed files
with
221 additions
and
215 deletions.
There are no files selected for viewing
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | ||
} |
Oops, something went wrong.