Skip to content

Commit 2c7f9a6

Browse files
authored
#3057. Add pattern assignment cases to for-in tests (#3130)
1 parent fa9304b commit 2c7f9a6

7 files changed

+405
-10
lines changed

TypeSystem/flow-analysis/reachability_for_in_A02_t02.dart

Lines changed: 34 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,9 +13,42 @@
1313
/// that if a variable is assigned in `E` then it is definitely assigned in `S`.
1414
/// @author [email protected]
1515
16-
main() {
16+
class C {
17+
int v;
18+
C(this.v);
19+
}
20+
21+
test1() {
1722
int i;
1823
for (var j in [i = 42]) {
1924
i; // Definitely assigned
2025
}
2126
}
27+
28+
test2() {
29+
int i;
30+
for (var j in [(i,) = (42,)]) {
31+
i; // Definitely assigned
32+
}
33+
}
34+
35+
test3() {
36+
int i;
37+
for (var j in [(x: i) = (x: 42)]) {
38+
i; // Definitely assigned
39+
}
40+
}
41+
42+
test4() {
43+
int i;
44+
for (var j in [C(v: i) = C(42)]) {
45+
i; // Definitely assigned
46+
}
47+
}
48+
49+
main() {
50+
test1();
51+
test2();
52+
test3();
53+
test4();
54+
}

TypeSystem/flow-analysis/reachability_for_in_A02_t04.dart

Lines changed: 76 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,11 @@
1414
/// analysis.
1515
/// @author [email protected]
1616
17+
class C {
18+
int v;
19+
C(this.v);
20+
}
21+
1722
test1(int? n) {
1823
if (n != null) { // n promoted to `int`
1924
for (var i in [() {n = 42;}]) { // n demoted to `int?`
@@ -26,8 +31,71 @@ test1(int? n) {
2631
}
2732

2833
test2(int? n) {
29-
if (n != null) { // n promoted to `int`
30-
for (var i in [() {n = 42;}]) {} // n demoted to `int?`
34+
if (n != null) {
35+
for (var i in [() {(n,) = (42,);}]) {
36+
n.isEven;
37+
// ^^^^^^
38+
// [analyzer] unspecified
39+
// [cfe] unspecified
40+
}
41+
}
42+
}
43+
44+
test3(int? n) {
45+
if (n != null) {
46+
for (var i in [() {(x: n) = (x: 42);}]) {
47+
n.isEven;
48+
// ^^^^^^
49+
// [analyzer] unspecified
50+
// [cfe] unspecified
51+
}
52+
}
53+
}
54+
55+
test4(int? n) {
56+
if (n != null) {
57+
for (var i in [() {C(v: n) = C(42);}]) {
58+
n.isEven;
59+
// ^^^^^^
60+
// [analyzer] unspecified
61+
// [cfe] unspecified
62+
}
63+
}
64+
}
65+
66+
test5(int? n) {
67+
if (n != null) {
68+
for (var i in [() {n = 42;}]) {}
69+
n.isEven;
70+
// ^^^^^^
71+
// [analyzer] unspecified
72+
// [cfe] unspecified
73+
}
74+
}
75+
76+
test6(int? n) {
77+
if (n != null) {
78+
for (var i in [() {(n,) = (42,);}]) {}
79+
n.isEven;
80+
// ^^^^^^
81+
// [analyzer] unspecified
82+
// [cfe] unspecified
83+
}
84+
}
85+
86+
test7(int? n) {
87+
if (n != null) {
88+
for (var i in [() {(x: n) = (x: 42);}]) {}
89+
n.isEven;
90+
// ^^^^^^
91+
// [analyzer] unspecified
92+
// [cfe] unspecified
93+
}
94+
}
95+
96+
test8(int? n) {
97+
if (n != null) {
98+
for (var i in [() {C(v: n) = C(42);}]) {}
3199
n.isEven;
32100
// ^^^^^^
33101
// [analyzer] unspecified
@@ -38,4 +106,10 @@ test2(int? n) {
38106
main() {
39107
print(test1);
40108
print(test2);
109+
print(test3);
110+
print(test4);
111+
print(test5);
112+
print(test6);
113+
print(test7);
114+
print(test8);
41115
}

TypeSystem/flow-analysis/reachability_for_in_A02_t05.dart

Lines changed: 91 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,11 @@
1414
/// analysis.
1515
/// @author [email protected]
1616
17+
class C {
18+
int v;
19+
C(this.v);
20+
}
21+
1722
test1(int? n) {
1823
if (n != null) { // n promoted to `int`
1924
for (var i in [42]) {
@@ -27,14 +32,92 @@ test1(int? n) {
2732
}
2833

2934
test2(int? n) {
30-
if (n != null) { // n promoted to `int`
35+
if (n != null) {
36+
for (var i in [42]) {
37+
late (int?,) x = ((n,) = (42,));
38+
n.isEven;
39+
// ^^^^^^
40+
// [analyzer] unspecified
41+
// [cfe] unspecified
42+
}
43+
}
44+
}
45+
46+
test3(int? n) {
47+
if (n != null) {
48+
for (var i in [42]) {
49+
late ({int? x}) x = ((x: n) = (x: 42));
50+
n.isEven;
51+
// ^^^^^^
52+
// [analyzer] unspecified
53+
// [cfe] unspecified
54+
}
55+
}
56+
}
57+
58+
test4(int? n) {
59+
if (n != null) {
60+
for (var i in [42]) {
61+
late C x = (C(v: n) = C(42));
62+
n.isEven;
63+
// ^^^^^^
64+
// [analyzer] unspecified
65+
// [cfe] unspecified
66+
}
67+
}
68+
}
69+
70+
test5(int? n) {
71+
if (n != null) {
72+
for (var j in [42]) {
73+
n.isEven;
74+
// ^^^^^^
75+
// [analyzer] unspecified
76+
// [cfe] unspecified
77+
() {
78+
n = 42;
79+
};
80+
}
81+
}
82+
}
83+
84+
test6(int? n) {
85+
if (n != null) {
86+
for (var j in [42]) {
87+
n.isEven;
88+
// ^^^^^^
89+
// [analyzer] unspecified
90+
// [cfe] unspecified
91+
() {
92+
(n,) = (42,);
93+
};
94+
}
95+
}
96+
}
97+
98+
test7(int? n) {
99+
if (n != null) {
100+
for (var j in [42]) {
101+
n.isEven;
102+
// ^^^^^^
103+
// [analyzer] unspecified
104+
// [cfe] unspecified
105+
() {
106+
(x: n) = (x: 42);
107+
};
108+
}
109+
}
110+
}
111+
112+
test8(int? n) {
113+
if (n != null) {
31114
for (var j in [42]) {
32115
n.isEven;
33116
// ^^^^^^
34117
// [analyzer] unspecified
35118
// [cfe] unspecified
36119
() {
37-
n = 42; // n demoted to `int?`
120+
C(v: n) = C(42);
38121
};
39122
}
40123
}
@@ -43,4 +126,10 @@ test2(int? n) {
43126
main() {
44127
print(test1);
45128
print(test2);
129+
print(test3);
130+
print(test4);
131+
print(test5);
132+
print(test6);
133+
print(test7);
134+
print(test8);
46135
}

TypeSystem/flow-analysis/reachability_for_in_A02_t06.dart

Lines changed: 34 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,14 +15,46 @@
1515
/// @author [email protected]
1616
/// @issue 60376
1717
18-
test(int? n) {
18+
class C {
19+
int v;
20+
C(this.v);
21+
}
22+
23+
test1(int? n) {
1924
if (n != null) { // n promoted to `int`
2025
for (var i in <int>[42, n]) { // Ok, n is still `int` here.
2126
late int? x = (n = 42); // n demoted to `int?`
2227
}
2328
}
2429
}
2530

31+
test2(int? n) {
32+
if (n != null) {
33+
for (var i in <int>[42, n]) {
34+
late (int?,) x = ((n,) = (42,));
35+
}
36+
}
37+
}
38+
39+
test3(int? n) {
40+
if (n != null) {
41+
for (var i in <int>[42, n]) {
42+
late ({int? x}) x = ((x: n) = (x: 42));
43+
}
44+
}
45+
}
46+
47+
test4(int? n) {
48+
if (n != null) {
49+
for (var i in <int>[42, n]) {
50+
late C x = (C(v: n) = C(42));
51+
}
52+
}
53+
}
54+
2655
main() {
27-
print(test);
56+
print(test1);
57+
print(test2);
58+
print(test3);
59+
print(test4);
2860
}

TypeSystem/flow-analysis/reachability_for_in_A03_t02.dart

Lines changed: 46 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,12 @@
1313
/// analysis as possibly assigned.
1414
/// @author [email protected]
1515
16-
main() {
16+
class C {
17+
int v;
18+
C(this.v);
19+
}
20+
21+
test1() {
1722
late int i;
1823
if (2 > 1) {
1924
for (var j in [42]) {
@@ -23,3 +28,43 @@ main() {
2328
}
2429
i; // Possibly assigned.
2530
}
31+
32+
test2() {
33+
late int i;
34+
if (2 > 1) {
35+
for (var j in [42]) {
36+
(i,) = (42,);
37+
break;
38+
}
39+
}
40+
i;
41+
}
42+
43+
test3() {
44+
late int i;
45+
if (2 > 1) {
46+
for (var j in [42]) {
47+
(x: i) = (x: 42);
48+
break;
49+
}
50+
}
51+
i;
52+
}
53+
54+
test4() {
55+
late int i;
56+
if (2 > 1) {
57+
for (var j in [42]) {
58+
C(v: i) = C(42);
59+
break;
60+
}
61+
}
62+
i;
63+
}
64+
65+
main() {
66+
test1();
67+
test2();
68+
test3();
69+
test4();
70+
}

0 commit comments

Comments
 (0)