Skip to content

Commit 1ac4e03

Browse files
authored
#3057. Add pattern assignment cases to do-while tests (#3124)
* #3122. Add pattern assignment cases to do-while tests * Fix typo in reachability_do_while_A01_t02.dart
1 parent 2505ba8 commit 1ac4e03

5 files changed

+217
-4
lines changed

TypeSystem/flow-analysis/reachability_do_while_A01_t01.dart

Lines changed: 43 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,12 @@
1212
/// definitely unassigned in `S`.
1313
/// @author [email protected]
1414
15-
main() {
15+
class C {
16+
int v;
17+
C(this.v);
18+
}
19+
20+
test1() {
1621
late int i;
1722
do {
1823
if (1 > 2) {
@@ -21,3 +26,40 @@ main() {
2126
i = 42;
2227
} while (false);
2328
}
29+
30+
test2() {
31+
late int i;
32+
do {
33+
if (1 > 2) {
34+
i; // Not definitely unassigned
35+
};
36+
(i,) = (42,);
37+
} while (false);
38+
}
39+
40+
test3() {
41+
late int i;
42+
do {
43+
if (1 > 2) {
44+
i; // Not definitely unassigned
45+
};
46+
(x: i) = (x: 42);
47+
} while (false);
48+
}
49+
50+
test4() {
51+
late int i;
52+
do {
53+
if (1 > 2) {
54+
i; // Not definitely unassigned
55+
};
56+
C(v: i) = C(42);
57+
} while (false);
58+
}
59+
60+
main() {
61+
test1();
62+
test2();
63+
test3();
64+
test4();
65+
}

TypeSystem/flow-analysis/reachability_do_while_A01_t02.dart

Lines changed: 34 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,9 +12,42 @@
1212
/// definitely unassigned in `E`.
1313
/// @author [email protected]
1414
15-
main() {
15+
class C {
16+
int v;
17+
C(this.v);
18+
}
19+
20+
test1() {
1621
late int i;
1722
do {
1823
i = 42;
1924
} while (i < 0);
2025
}
26+
27+
test2() {
28+
late int i;
29+
do {
30+
(i,) = (42,);
31+
} while (i < 0);
32+
}
33+
34+
test3() {
35+
late int i;
36+
do {
37+
(x: i) = (x: 42);
38+
} while (i < 0);
39+
}
40+
41+
test4() {
42+
late int i;
43+
do {
44+
C(v: i) = C(42);
45+
} while (i < 0);
46+
}
47+
48+
main() {
49+
test1();
50+
test2();
51+
test3();
52+
test4();
53+
}

TypeSystem/flow-analysis/reachability_do_while_A01_t03.dart

Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,11 @@
1212
/// detected by flow analysis of `S`.
1313
/// @author [email protected]
1414
15+
class C {
16+
int v;
17+
C(this.v);
18+
}
19+
1520
test1(int? n) {
1621
if (n != null) { // promoted to `int`
1722
do {
@@ -38,7 +43,52 @@ test2(int? n) {
3843
}
3944
}
4045

46+
test3(int? n) {
47+
if (n != null) { // promoted to `int`
48+
do {
49+
() {
50+
(n,) = (42,); // demoted to `int?`
51+
};
52+
n.isEven;
53+
// ^^^^^^
54+
// [analyzer] unspecified
55+
// [cfe] unspecified
56+
} while (false);
57+
}
58+
}
59+
60+
test4(int? n) {
61+
if (n != null) { // promoted to `int`
62+
do {
63+
() {
64+
(x: n) = (x: 42); // demoted to `int?`
65+
};
66+
n.isEven;
67+
// ^^^^^^
68+
// [analyzer] unspecified
69+
// [cfe] unspecified
70+
} while (false);
71+
}
72+
}
73+
74+
test5(int? n) {
75+
if (n != null) { // promoted to `int`
76+
do {
77+
() {
78+
C(v: n) = C(42); // demoted to `int?`
79+
};
80+
n.isEven;
81+
// ^^^^^^
82+
// [analyzer] unspecified
83+
// [cfe] unspecified
84+
} while (false);
85+
}
86+
}
87+
4188
main() {
4289
print(test1);
4390
print(test2);
91+
print(test3);
92+
print(test4);
93+
print(test5);
4494
}

TypeSystem/flow-analysis/reachability_do_while_A01_t04.dart

Lines changed: 49 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,12 @@
1212
/// detected by flow analysis of `E`.
1313
/// @author [email protected]
1414
15-
test(int? n) {
15+
class C {
16+
int v;
17+
C(this.v);
18+
}
19+
20+
test1(int? n) {
1621
if (n != null) { // promoted to `int`
1722
do {
1823
() {
@@ -25,6 +30,48 @@ test(int? n) {
2530
}
2631
}
2732

33+
test2(int? n) {
34+
if (n != null) { // promoted to `int`
35+
do {
36+
() {
37+
(n,) = (42,); // demoted to `int?`
38+
};
39+
} while (n > 0);
40+
// ^
41+
// [analyzer] unspecified
42+
// [cfe] unspecified
43+
}
44+
}
45+
46+
test3(int? n) {
47+
if (n != null) { // promoted to `int`
48+
do {
49+
() {
50+
(x: n) = (x: 42); // demoted to `int?`
51+
};
52+
} while (n > 0);
53+
// ^
54+
// [analyzer] unspecified
55+
// [cfe] unspecified
56+
}
57+
}
58+
59+
test4(int? n) {
60+
if (n != null) { // promoted to `int`
61+
do {
62+
() {
63+
C(v: n) = C(42); // demoted to `int?`
64+
};
65+
} while (n > 0);
66+
// ^
67+
// [analyzer] unspecified
68+
// [cfe] unspecified
69+
}
70+
}
71+
2872
main() {
29-
print(test);
73+
print(test1);
74+
print(test2);
75+
print(test3);
76+
print(test4);
3077
}

TypeSystem/flow-analysis/reachability_do_while_A01_t05.dart

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,11 @@
1111
/// @description Checks that `capturedIn(E)` is detected by flow analysis.
1212
/// @author [email protected]
1313
14+
class C {
15+
int v;
16+
C(this.v);
17+
}
18+
1419
test1(int? n) {
1520
if (n != null) { // n promoted to `int`
1621
do {
@@ -33,7 +38,43 @@ test2(int? n) {
3338
}
3439
}
3540

41+
test3(int? n) {
42+
if (n != null) { // n promoted to `int`
43+
do {
44+
n.isEven;
45+
// ^^^^^^
46+
// [analyzer] unspecified
47+
// [cfe] unspecified
48+
} while (() {(n,) = (42,); return false;}()); // n demoted to `int?`
49+
}
50+
}
51+
52+
test4(int? n) {
53+
if (n != null) { // n promoted to `int`
54+
do {
55+
n.isEven;
56+
// ^^^^^^
57+
// [analyzer] unspecified
58+
// [cfe] unspecified
59+
} while (() {(x: n) = (x: 42); return false;}()); // n demoted to `int?`
60+
}
61+
}
62+
63+
test5(int? n) {
64+
if (n != null) { // n promoted to `int`
65+
do {
66+
n.isEven;
67+
// ^^^^^^
68+
// [analyzer] unspecified
69+
// [cfe] unspecified
70+
} while (() {C(v: n) = C(42); return false;}()); // n demoted to `int?`
71+
}
72+
}
73+
3674
main() {
3775
print(test1);
3876
print(test2);
77+
print(test3);
78+
print(test4);
79+
print(test5);
3980
}

0 commit comments

Comments
 (0)