Skip to content

Commit abbb7f1

Browse files
authored
#2420. Add another variable pattern exhaustiveness test (#2469)
Add another variable pattern exhaustiveness test
1 parent 044abd3 commit abbb7f1

File tree

1 file changed

+86
-0
lines changed

1 file changed

+86
-0
lines changed
Lines changed: 86 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,86 @@
1+
// Copyright (c) 2024, the Dart project authors. Please see the AUTHORS file
2+
// for details. All rights reserved. Use of this source code is governed by a
3+
// BSD-style license that can be found in the LICENSE file.
4+
5+
/// @assertion Exhaustiveness of a variable pattern is determined by the static
6+
/// type of the corresponding variable.
7+
///
8+
/// @description Check that the lifted space union of a variable pattern is
9+
/// determined by the static type of the corresponding variable.
10+
/// @author [email protected]
11+
12+
// SharedOptions=--enable-experiment=inline-class
13+
14+
import "../../Utils/expect.dart";
15+
16+
extension type BoolET1(bool _) {}
17+
extension type BoolET2(bool _) implements bool {}
18+
19+
String test1_1(BoolET1 o) {
20+
switch (o) {
21+
case bool _b:
22+
return "exhaustive";
23+
}
24+
}
25+
26+
String test1_2(BoolET2 o) {
27+
switch (o) {
28+
case bool _b:
29+
return "exhaustive";
30+
}
31+
}
32+
33+
String test1_3(BoolET1 o) {
34+
switch (o) {
35+
case BoolET1 _b:
36+
return "exhaustive";
37+
}
38+
}
39+
40+
String test1_4(BoolET2 o) {
41+
switch (o) {
42+
case BoolET2 _b:
43+
return "exhaustive";
44+
}
45+
}
46+
47+
String test1_5(BoolET1 o) {
48+
switch (o) {
49+
case BoolET2 _b:
50+
return "exhaustive";
51+
}
52+
}
53+
54+
String test1_6(BoolET2 o) {
55+
switch (o) {
56+
case BoolET1 _b:
57+
return "exhaustive";
58+
}
59+
}
60+
61+
String test2_1(BoolET1 o) => switch (o) {
62+
var v => "exhaustive"
63+
};
64+
65+
String test2_2(BoolET2 o) => switch (o) {
66+
var v => "exhaustive"
67+
};
68+
69+
main() {
70+
Expect.equals("exhaustive", test1_1(BoolET1(true)));
71+
Expect.equals("exhaustive", test1_1(BoolET1(false)));
72+
Expect.equals("exhaustive", test1_2(BoolET2(true)));
73+
Expect.equals("exhaustive", test1_2(BoolET2(false)));
74+
Expect.equals("exhaustive", test1_3(BoolET1(true)));
75+
Expect.equals("exhaustive", test1_3(BoolET1(false)));
76+
Expect.equals("exhaustive", test1_4(BoolET2(true)));
77+
Expect.equals("exhaustive", test1_4(BoolET2(false)));
78+
Expect.equals("exhaustive", test1_5(BoolET1(true)));
79+
Expect.equals("exhaustive", test1_5(BoolET1(false)));
80+
Expect.equals("exhaustive", test1_6(BoolET2(true)));
81+
Expect.equals("exhaustive", test1_6(BoolET2(false)));
82+
Expect.equals("exhaustive", test2_1(BoolET1(true)));
83+
Expect.equals("exhaustive", test2_1(BoolET1(false)));
84+
Expect.equals("exhaustive", test2_2(BoolET2(true)));
85+
Expect.equals("exhaustive", test2_2(BoolET2(false)));
86+
}

0 commit comments

Comments
 (0)