Skip to content

Commit 398b637

Browse files
authored
#3057. Add conditional statements tests (#3106)
Add conditional statements tests
1 parent 1d13f7c commit 398b637

File tree

91 files changed

+440
-103
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

91 files changed

+440
-103
lines changed

TypeSystem/flow-analysis/definite_assignment_A02_t01.dart

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,16 +2,18 @@
22
// for details. All rights reserved. Use of this source code is governed by a
33
// BSD-style license that can be found in the LICENSE file.
44

5-
/// @assertion assigned is a boolean value indicating whether the variable has
6-
/// definitely been assigned at the given point in the source code. When assigned
7-
/// is true, we say that the variable is definitely assigned at that point.
5+
/// @assertion `assigned` is a boolean value indicating whether the variable has
6+
/// definitely been assigned at the given point in the source code. When
7+
/// `assigned` is true, we say that the variable is definitely assigned at that
8+
/// point.
89
///
9-
/// @description Checks definite assignment and if statement
10+
/// @description Checks that if variable assigned in both branches of `if`
11+
/// statement then it is definitely assigned.
1012
/// @author [email protected]
1113
1214
main() {
1315
int n;
14-
bool b = true;
16+
bool b = 2 > 1;
1517
if (b) {
1618
n = 42;
1719
} else {

TypeSystem/flow-analysis/definite_assignment_A02_t02.dart

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,11 +2,14 @@
22
// for details. All rights reserved. Use of this source code is governed by a
33
// BSD-style license that can be found in the LICENSE file.
44

5-
/// @assertion assigned is a boolean value indicating whether the variable has
6-
/// definitely been assigned at the given point in the source code. When assigned
7-
/// is true, we say that the variable is definitely assigned at that point.
5+
/// @assertion `assigned` is a boolean value indicating whether the variable has
6+
/// definitely been assigned at the given point in the source code. When
7+
/// `assigned` is true, we say that the variable is definitely assigned at that
8+
/// point.
89
///
9-
/// @description Checks definite assignment and if statement
10+
/// @description Checks that if a variable is assigned only in one branch of an
11+
/// `if` statement and the condition is not `true` or `false` literal then it is
12+
/// not definitely assigned.
1013
/// @author [email protected]
1114
1215
main() {

TypeSystem/flow-analysis/definite_assignment_A02_t03.dart

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,11 +2,14 @@
22
// for details. All rights reserved. Use of this source code is governed by a
33
// BSD-style license that can be found in the LICENSE file.
44

5-
/// @assertion assigned is a boolean value indicating whether the variable has
6-
/// definitely been assigned at the given point in the source code. When assigned
7-
/// is true, we say that the variable is definitely assigned at that point.
5+
/// @assertion `assigned` is a boolean value indicating whether the variable has
6+
/// definitely been assigned at the given point in the source code. When
7+
/// `assigned` is true, we say that the variable is definitely assigned at that
8+
/// point.
89
///
9-
/// @description Checks definite assignment and if statement
10+
/// @description Checks that if a variable is assigned only in one branch of an
11+
/// `if` statement and the condition is not `true` or `false` literal then it is
12+
/// not definitely assigned.
1013
/// @author [email protected]
1114
1215
main() {

TypeSystem/flow-analysis/definite_assignment_A02_t04.dart

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,11 +2,14 @@
22
// for details. All rights reserved. Use of this source code is governed by a
33
// BSD-style license that can be found in the LICENSE file.
44

5-
/// @assertion assigned is a boolean value indicating whether the variable has
6-
/// definitely been assigned at the given point in the source code. When assigned
7-
/// is true, we say that the variable is definitely assigned at that point.
5+
/// @assertion `assigned` is a boolean value indicating whether the variable has
6+
/// definitely been assigned at the given point in the source code. When
7+
/// `assigned` is true, we say that the variable is definitely assigned at that
8+
/// point.
89
///
9-
/// @description Checks definite assignment and if statement
10+
/// @description Checks that if variable assigned in the `then` branch of `if`
11+
/// statement and the condition is the `true` literal then it is definitely
12+
/// assigned.
1013
/// @author [email protected]
1114
1215
main() {

TypeSystem/flow-analysis/definite_assignment_A02_t05.dart

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,11 +2,14 @@
22
// for details. All rights reserved. Use of this source code is governed by a
33
// BSD-style license that can be found in the LICENSE file.
44

5-
/// @assertion assigned is a boolean value indicating whether the variable has
6-
/// definitely been assigned at the given point in the source code. When assigned
7-
/// is true, we say that the variable is definitely assigned at that point.
5+
/// @assertion `assigned` is a boolean value indicating whether the variable has
6+
/// definitely been assigned at the given point in the source code. When
7+
/// `assigned` is true, we say that the variable is definitely assigned at that
8+
/// point.
89
///
9-
/// @description Checks definite assignment and if statement
10+
/// @description Checks that if variable assigned in the `else` branch of `if`
11+
/// statement and the condition is the `false` literal then it is definitely
12+
/// assigned.
1013
/// @author [email protected]
1114
1215
main() {

TypeSystem/flow-analysis/reachability_A01_t01.dart

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ void test(Never n) {
1919
bool b = (() => true)();
2020
if (b) {
2121
n; // The code after this point is unreachable
22-
i = 42; // Variable is initialized in a dead code. This leaves it definitely unassigned
22+
i = 42; // This is dead code, which leaves `i` definitely unassigned.
2323
}
2424
i; // It is an error to read a local late variable when it is definitely unassigned.
2525
//^

TypeSystem/flow-analysis/reachability_A01_t02.dart

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ main() {
2222
bool b = (() => true)();
2323
if (b) {
2424
n; // The code after this point is unreachable
25-
i = 42; // Variable is initialized in a dead code. This leaves it definitely unassigned
25+
i = 42; // This is dead code, which leaves `i` definitely unassigned.
2626
}
2727
i; // It is an error to read a local late variable when it is definitely unassigned.
2828
// ^

TypeSystem/flow-analysis/reachability_A01_t11.dart

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ void test<T extends Never>(T n) {
1919
bool b = (() => true)();
2020
if (b) {
2121
n; // The code after this point is unreachable
22-
i = 42; // Variable is initialized in a dead code. This leaves it definitely unassigned
22+
i = 42; // This is dead code, which leaves `i` definitely unassigned.
2323
}
2424
i; // It is an error to read a local late variable when it is definitely unassigned.
2525
//^

TypeSystem/flow-analysis/reachability_A01_t12.dart

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ class C<T extends Never> {
2323
bool b = (() => true)();
2424
if (b) {
2525
n; // The code after this point is unreachable
26-
i = 42; // Variable is initialized in a dead code. This leaves it definitely unassigned
26+
i = 42; // This is dead code, which leaves `i` definitely unassigned.
2727
}
2828
i; // It is an error to read a local late variable when it is definitely unassigned.
2929
// ^

TypeSystem/flow-analysis/reachability_A01_t17.dart

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ void test(Never n) {
2020
if (b) {
2121
[
2222
n, // The code after this point is unreachable
23-
i = 42 // Variable is initialized in a dead code. This leaves it definitely unassigned
23+
i = 42 // This is dead code, which leaves `i` definitely unassigned.
2424
];
2525
}
2626
i; // It is an error to read a local late variable when it is definitely unassigned.

0 commit comments

Comments
 (0)