OLD | NEW |
---|---|
1 // Copyright (c) 2016, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2016, the Dart project authors. Please see the AUTHORS file |
2 // for details. All rights reserved. Use of this source code is governed by a | 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. | 3 // BSD-style license that can be found in the LICENSE file. |
4 // Test switch statement. | 4 // Test switch statement. |
5 | 5 |
6 // Tests some switch-case statements blocks that should and should not | 6 // Tests some switch-case statements blocks that should and should not |
7 // cause static warnings. | 7 // cause static warnings. |
8 // This test is not testing runtime behavior, only static warnings. | 8 // This test is not testing runtime behavior, only static warnings. |
9 | 9 |
10 // None of the cases blocks should cause a warning. | 10 // None of the cases blocks should cause a warning. |
(...skipping 16 matching lines...) Expand all Loading... | |
27 case 3: | 27 case 3: |
28 nop(x); | 28 nop(x); |
29 continue; // Continue loop. | 29 continue; // Continue loop. |
30 case 4: | 30 case 4: |
31 nop(x); | 31 nop(x); |
32 continue LOOP; | 32 continue LOOP; |
33 case 5: | 33 case 5: |
34 nop(x); | 34 nop(x); |
35 continue LAST; | 35 continue LAST; |
36 // Avoid warning for "return;"" and "return e;" in same function. | 36 // Avoid warning for "return;"" and "return e;" in same function. |
37 case 6: /// retnon: ok | 37 case 6: // /// retnon: ok |
38 nop(x); /// retnon: continued | 38 nop(x); // /// retnon: continued |
39 return; /// retnon: continued | 39 return; // /// retnon: continued |
40 case 7: /// retval: ok | 40 case 7: // /// retval: ok |
41 nop(x); /// retval: continued | 41 nop(x); // /// retval: continued |
42 return x; /// retval: continued | 42 return x; // /// retval: continued |
43 case 8: | 43 case 8: |
44 nop(x); | 44 nop(x); |
45 throw x; | 45 throw x; |
46 case 9: | 46 case 9: |
47 nop(x); | 47 nop(x); |
48 rethrow; | 48 rethrow; |
49 case 10: | 49 case 10: |
50 case 11: { | 50 case 11: { |
51 nop(x); | 51 nop(x); |
52 break; // Break switch. | 52 break; // Break switch. |
53 } | 53 } |
54 case 12: { | 54 case 12: { |
55 nop(x); | 55 nop(x); |
56 break LOOP; | 56 break LOOP; |
57 } | 57 } |
58 case 13: { | 58 case 13: { |
59 nop(x); | 59 nop(x); |
60 continue; // Continue loop. | 60 continue; // Continue loop. |
61 } | 61 } |
62 case 14: { | 62 case 14: { |
63 nop(x); | 63 nop(x); |
64 continue LOOP; | 64 continue LOOP; |
65 } | 65 } |
66 case 15: { | 66 case 15: { |
67 nop(x); | 67 nop(x); |
68 continue LAST; | 68 continue LAST; |
69 } | 69 } |
70 case 16: { /// retnon: continued | 70 case 16: { // /// retnon: continued |
71 nop(x); /// retnon: continued | 71 nop(x); // /// retnon: continued |
72 return; /// retnon: continued | 72 return; // /// retnon: continued |
73 } /// retnon: continued | 73 } // /// retnon: continued |
74 case 17: { /// retval: continued | 74 case 17: { // /// retval: continued |
75 nop(x); /// retval: continued | 75 nop(x); // /// retval: continued |
76 return x; /// retval: continued | 76 return x; // /// retval: continued |
77 } /// retval: continued | 77 } // /// retval: continued |
78 case 18: { | 78 case 18: { |
79 nop(x); | 79 nop(x); |
80 throw x; | 80 throw x; |
81 } | 81 } |
82 case 19: { | 82 case 19: { |
83 nop(x); | 83 nop(x); |
84 rethrow; | 84 rethrow; |
85 } | 85 } |
86 LAST: | 86 LAST: |
87 case 20: { | 87 case 20: { |
(...skipping 12 matching lines...) Expand all Loading... | |
100 | 100 |
101 // All these switch cases should cause warnings. | 101 // All these switch cases should cause warnings. |
102 void testSwitchWarn(x) { | 102 void testSwitchWarn(x) { |
103 // Catch all control flow from the switch and ignore it. | 103 // Catch all control flow from the switch and ignore it. |
104 TRY: try { | 104 TRY: try { |
105 throw 0; | 105 throw 0; |
106 } catch (e) { | 106 } catch (e) { |
107 // Wrap in loop as target for continue/break. | 107 // Wrap in loop as target for continue/break. |
108 LOOP: do { | 108 LOOP: do { |
109 switch (x) { | 109 switch (x) { |
110 case 0: /// 01: static type warning | 110 case 0: // /// 01: static type warning |
111 case 1: { /// 01: continued | 111 case 1: { // /// 01: continued |
112 { /// 01: continued | 112 { // /// 01: continued |
113 nop(x); /// 01: continued | 113 nop(x); // /// 01: continued |
114 break; // Break switch. /// 01: continued | 114 break; // Break switch. // /// 01: continued |
115 } /// 01: continued | 115 } // /// 01: continued |
116 } /// 01: continued | 116 } // /// 01: continued |
117 case 2: { /// 02: static type warning | 117 case 2: { // /// 02: static type warning |
118 { /// 02: continued | 118 { // /// 02: continued |
119 nop(x); /// 02: continued | 119 nop(x); // /// 02: continued |
120 break LOOP; /// 02: continued | 120 break LOOP; // /// 02: continued |
121 } /// 02: continued | 121 } // /// 02: continued |
122 } /// 02: continued | 122 } // /// 02: continued |
123 case 3: { /// 03: static type warning | 123 case 3: { // /// 03: static type warning |
124 { /// 03: continued | 124 { // /// 03: continued |
125 nop(x); /// 03: continued | 125 nop(x); // /// 03: continued |
126 continue; // Continue loop. /// 03: continued | 126 continue; // Continue loop. /// 03: continued |
sra1
2017/03/21 03:28:14
fix?
| |
127 } /// 03: continued | 127 } // /// 03: continued |
128 } /// 03: continued | 128 } // /// 03: continued |
129 case 4: { /// 04: static type warning | 129 case 4: { // /// 04: static type warning |
130 { /// 04: continued | 130 { // /// 04: continued |
131 nop(x); /// 04: continued | 131 nop(x); // /// 04: continued |
132 continue LOOP; /// 04: continued | 132 continue LOOP; // /// 04: continued |
133 } /// 04: continued | 133 } // /// 04: continued |
134 } /// 04: continued | 134 } // /// 04: continued |
135 case 5: { /// 05: static type warning | 135 case 5: { // /// 05: static type warning |
136 { /// 05: continued | 136 { // /// 05: continued |
137 nop(x); /// 05: continued | 137 nop(x); // /// 05: continued |
138 continue LAST; /// 05: continued | 138 continue LAST; // /// 05: continued |
139 } /// 05: continued | 139 } // /// 05: continued |
140 } /// 05: continued | 140 } // /// 05: continued |
141 case 6: { /// 06: static type warning | 141 case 6: { // /// 06: static type warning |
142 { /// 06: continued | 142 { // /// 06: continued |
143 nop(x); /// 06: continued | 143 nop(x); // /// 06: continued |
144 return; /// 06: continued | 144 return; // /// 06: continued |
145 } /// 06: continued | 145 } // /// 06: continued |
146 } /// 06: continued | 146 } // /// 06: continued |
147 case 7: { /// 07: static type warning | 147 case 7: { // /// 07: static type warning |
148 { /// 07: continued | 148 { // /// 07: continued |
149 nop(x); /// 07: continued | 149 nop(x); // /// 07: continued |
150 return x; /// 07: continued | 150 return x; // /// 07: continued |
151 } /// 07: continued | 151 } // /// 07: continued |
152 } /// 07: continued | 152 } // /// 07: continued |
153 case 8: { /// 08: static type warning | 153 case 8: { // /// 08: static type warning |
154 { /// 08: continued | 154 { // /// 08: continued |
155 nop(x); /// 08: continued | 155 nop(x); // /// 08: continued |
156 throw x; /// 08: continued | 156 throw x; // /// 08: continued |
157 } /// 08: continued | 157 } // /// 08: continued |
158 } /// 08: continued | 158 } // /// 08: continued |
159 case 9: { /// 09: static type warning | 159 case 9: { // /// 09: static type warning |
160 { /// 09: continued | 160 { // /// 09: continued |
161 nop(x); /// 09: continued | 161 nop(x); // /// 09: continued |
162 rethrow; /// 09: continued | 162 rethrow; // /// 09: continued |
163 } /// 09: continued | 163 } // /// 09: continued |
164 } /// 09: continued | 164 } // /// 09: continued |
165 case 10: /// 10: static type warning | 165 case 10: // /// 10: static type warning |
166 while (true) break; /// 10: continued | 166 while (true) break; // /// 10: continued |
167 case 11: /// 11: static type warning | 167 case 11: // /// 11: static type warning |
168 do break; while (true); /// 11: continued | 168 do break; while (true); // /// 11: continued |
169 case 12: /// 12: static type warning | 169 case 12: // /// 12: static type warning |
170 for (;;) break; /// 12: continued | 170 for (;;) break; // /// 12: continued |
171 case 13: /// 13: static type warning | 171 case 13: // /// 13: static type warning |
172 for (var _ in []) break; /// 13: continued | 172 for (var _ in []) break; // /// 13: continued |
173 case 14: /// 14: static type warning | 173 case 14: // /// 14: static type warning |
174 if (x) break; else break; /// 14: continued | 174 if (x) break; else break; // /// 14: continued |
175 case 15: /// 15: static type warning | 175 case 15: // /// 15: static type warning |
176 (throw 0); /// 15: continued | 176 (throw 0); // /// 15: continued |
177 case 16: /// 16: static type warning | 177 case 16: // /// 16: static type warning |
178 nop(x); // fallthrough. /// 16: continued | 178 nop(x); // fallthrough. // /// 16: continued |
179 case 17: /// 17: static type warning | 179 case 17: // /// 17: static type warning |
180 L: break; /// 17: continued | 180 L: break; // /// 17: continued |
181 LAST: | 181 LAST: |
182 case 99: | 182 case 99: |
183 // Last case can't cause static warning. | 183 // Last case can't cause static warning. |
184 } | 184 } |
185 } while (false); | 185 } while (false); |
186 } finally { | 186 } finally { |
187 // Catch all control flow leaving the switch and ignore it. | 187 // Catch all control flow leaving the switch and ignore it. |
188 // Use break instead of return to avoid warning for `return` and `return e` | 188 // Use break instead of return to avoid warning for `return` and `return e` |
189 // in same function. | 189 // in same function. |
190 break TRY; | 190 break TRY; |
191 } | 191 } |
192 } | 192 } |
193 | 193 |
194 main() { | 194 main() { |
195 // Ensure that all the cases compile and run (even if they might throw). | 195 // Ensure that all the cases compile and run (even if they might throw). |
196 for (int i = 0; i <= 20; i++) { | 196 for (int i = 0; i <= 20; i++) { |
197 testSwitch(i); // Just make sure it runs. | 197 testSwitch(i); // Just make sure it runs. |
198 } | 198 } |
199 for (int i = 0; i <= 18; i++) { | 199 for (int i = 0; i <= 18; i++) { |
200 testSwitchWarn(i); | 200 testSwitchWarn(i); |
201 } | 201 } |
202 } | 202 } |
203 | 203 |
204 /// Don't make it obvious that a switch case isn't doing anything. | 204 /// Don't make it obvious that a switch case isn't doing anything. |
205 void nop(x) {} | 205 void nop(x) {} |
OLD | NEW |