OLD | NEW |
---|---|
(Empty) | |
1 // Copyright (c) 2017, 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 // Test that `covariant` can be parsed (and ignored) by | |
6 // dart2js and the VM. | |
7 // This test only checks for non-strong mode behavior. | |
8 // | |
9 // Generally, `covariant` should be ignored, when it is used in the right | |
10 // places. | |
11 | |
12 import 'package:expect/expect.dart'; | |
13 | |
14 // Top level field may not have a covariant. | |
15 // Would be considered a minor (acceptable) bug, if it was accepted here too. | |
16 covariant /// 00: compile-time error | |
17 int x0; | |
18 | |
19 // Getters may never have `covariant`. (Neither on the top-level nor as members) | |
20 covariant /// 01: compile-time error | |
21 int get x1 => 499; | |
22 | |
23 // Top level setters may not have a covariant. | |
24 // Would be considered a minor (acceptable) bug, if it was accepted here too. | |
25 void set x2( | |
26 covariant /// 02: compile-time error | |
27 int val) {} | |
28 | |
29 // Same as above, but with `covariant` in different positions. | |
30 // The `covariant` is just wrong there. | |
31 | |
32 int | |
33 covariant /// 03: compile-time error | |
34 x3; | |
35 | |
36 int | |
37 covariant /// 04: compile-time error | |
38 get x4 => 499; | |
39 | |
40 void set x5( | |
41 int | |
42 covariant /// 05: compile-time error | |
43 val) {} | |
44 | |
45 | |
46 // Same without types. | |
47 | |
48 // Since `covariant` is a built-in identifier, it is not allowed here. | |
49 covariant x6; /// 06: compile-time error | |
50 | |
51 // Getters may never have `covariant`. | |
52 covariant /// 07: compile-time error | |
53 get x7 => 499; | |
54 | |
55 // Top level setters may not have a covariant. | |
56 // Would be considered a minor (acceptable) bug, if it was accepted here too. | |
57 void set x8( | |
58 covariant /// 08: compile-time error | |
59 val) {} | |
60 | |
61 // If there is no type, then `covariant` is simply the parameter name: | |
62 void set x9(covariant) {} | |
63 | |
64 // Covariant won't work on return types. | |
65 covariant /// 10: compile-time error | |
66 int f10() => 499; | |
67 | |
68 // Covariant won't work as a return type. | |
69 covariant /// 11: compile-time error | |
70 f11() => 499; | |
71 | |
72 // Covariant should not work on top-level methods. | |
73 // It's a minor (acceptable) bug to not error out here. | |
74 int f12( | |
75 covariant /// 12: compile-time error | |
76 int x) => 499; | |
77 | |
78 // `Covariant` must be in front of the types. | |
79 int f13( | |
80 int | |
81 covariant /// 13: compile-time error | |
82 x) => 499; | |
83 | |
84 // Covariant should not work on top-level methods. | |
85 // It's a minor (acceptable) bug to not error out here. | |
86 int f14( | |
87 covariant /// 14: compile-time error | |
88 final | |
89 x) => 499; | |
90 | |
91 // `Covariant` must be in front of modifiers. | |
92 int f15( | |
93 final | |
94 covariant /// 15: compile-time error | |
95 x) => 499; | |
96 | |
97 // Covariant should not work on top-level methods. | |
98 // It's a minor (acceptable) bug to not error out here. | |
99 int f16( | |
100 covariant /// 16: compile-time error | |
101 final | |
102 int | |
103 x) => 499; | |
104 | |
105 // `Covariant` must be in front of modifiers. | |
106 int f17( | |
107 final | |
108 covariant /// 17: compile-time error | |
109 int | |
110 x) => 499; | |
111 | |
112 // On its own, `covariant` is just a parameter name. | |
113 int f18(covariant) => covariant; | |
114 | |
115 // All of the above as statics in a class. | |
116 class A { | |
117 // Static fields may not have a covariant. | |
118 // Would be considered a minor (acceptable) bug, if it was accepted here too. | |
119 static | |
120 covariant /// 20: compile-time error | |
121 int x20; | |
122 | |
123 // Getters may never have `covariant`. | |
124 static | |
125 covariant /// 21: compile-time error | |
126 int get x21 => 499; | |
127 | |
128 // Getters may never have `covariant`. | |
129 covariant /// 21b: compile-time error | |
130 static | |
131 int get x21b => 499; | |
132 | |
133 // Static setters may not have a covariant. | |
134 // Would be considered a minor (acceptable) bug, if it was accepted here too. | |
135 static void set x22( | |
136 covariant /// 22: compile-time error | |
137 int val) {} | |
138 | |
139 // Same as above, but with `covariant` in different positions. | |
140 // The `covariant` is just wrong there. | |
141 | |
142 static int | |
143 covariant /// 23: compile-time error | |
144 x23; | |
145 | |
146 static int | |
147 covariant /// 24: compile-time error | |
148 get x24 => 499; | |
149 | |
150 static void set x25( | |
151 int | |
152 covariant /// 25: compile-time error | |
153 val) {} | |
154 | |
155 // Since `covariant` is a built-in identifier, it is not allowed here. | |
156 static covariant x26; /// 26: compile-time error | |
157 | |
158 // Getters may never have `covariant`. | |
159 static | |
160 covariant /// 27: compile-time error | |
161 get x27 => 499; | |
162 | |
163 covariant /// 27b: compile-time error | |
164 static | |
165 get x27b => 499; | |
166 | |
167 // Static setters may not have a covariant. | |
168 // Would be considered a minor (acceptable) bug, if it was accepted here too. | |
169 static void set x28( | |
170 covariant /// 28: compile-time error | |
171 val) {} | |
172 | |
173 // If there is no type, then `covariant` is simply the parameter name: | |
174 static void set x29(covariant) {} | |
175 | |
176 // Covariant won't work on return types. | |
177 static | |
178 covariant /// 30: compile-time error | |
179 int f30() => 499; | |
180 | |
181 covariant /// 30b: compile-time error | |
182 static | |
183 int f30b() => 499; | |
184 | |
185 // Covariant won't work as a return type. | |
186 static | |
187 covariant /// 31: compile-time error | |
188 f31() => 499; | |
189 | |
190 covariant /// 31b: compile-time error | |
191 static | |
192 f31b() => 499; | |
193 | |
194 // Covariant should not work on static methods. | |
195 // It's a minor (acceptable) bug to not error out here. | |
196 static int f32( | |
197 covariant /// 32: compile-time error | |
198 int x) => 499; | |
199 | |
200 // `Covariant` must be in front of the types. | |
201 static int f33( | |
202 int | |
203 covariant /// 33: compile-time error | |
204 x) => 499; | |
205 | |
206 // Covariant should not work on top-level methods. | |
207 // It's a minor (acceptable) bug to not error out here. | |
208 static int f34( | |
209 covariant /// 34: compile-time error | |
210 final | |
211 x) => 499; | |
212 | |
213 // `Covariant` must be in front of modifiers. | |
214 static int f35( | |
215 final | |
216 covariant /// 35: compile-time error | |
217 x) => 499; | |
218 | |
219 // Covariant should not work on top-level methods. | |
220 // It's a minor (acceptable) bug to not error out here. | |
221 static int f36( | |
222 covariant /// 36: compile-time error | |
223 final | |
224 int | |
225 x) => 499; | |
226 | |
227 // `Covariant` must be in front of modifiers. | |
228 static int f37( | |
229 final | |
230 covariant /// 37: compile-time error | |
231 int | |
232 x) => 499; | |
233 | |
234 // `Covariant` on its own is just a parameter name. | |
235 static int f38(covariant) => covariant; | |
236 } | |
237 | |
238 // All of the above as instance members in a class. | |
239 class B { | |
240 covariant int x40; | |
241 | |
242 // Getters may never have `covariant`. | |
243 covariant /// 41: compile-time error | |
244 int get x41 => 499; | |
245 | |
246 void set x42(covariant int val) {} | |
247 | |
248 // `covariant` in the wrong position. | |
249 int | |
250 covariant /// 43: compile-time error | |
251 x43; | |
252 | |
253 // `covariant` in the wrong position. | |
254 int | |
255 covariant /// 44: compile-time error | |
256 get x44 => 499; | |
257 | |
258 void set x45( | |
259 int | |
260 covariant /// 45: compile-time error | |
261 val) {} | |
262 | |
263 // Since `covariant` is a built-in identifier, it is not allowed here. | |
264 covariant x46; /// 46: compile-time error | |
265 | |
266 // Getters may never have `covariant`. | |
267 covariant /// 47: compile-time error | |
268 get x47 => 499; | |
269 | |
270 void set x48(covariant val) {} | |
271 | |
272 // If there is no type, then `covariant` is simply the parameter name: | |
273 void set x49(covariant) {} | |
274 | |
275 // Covariant won't work on return types. | |
276 covariant /// 50: compile-time error | |
277 int f50() => 499; | |
278 | |
279 // Covariant won't work as a return type. | |
280 covariant /// 51: compile-time error | |
281 f51() => 499; | |
282 | |
283 int f52(covariant int x) => 499; | |
284 | |
285 // `Covariant` must be in front of the types. | |
286 int f53( | |
287 int | |
288 covariant /// 53: compile-time error | |
289 x) => 499; | |
290 | |
291 int f54(covariant final x) => 499; | |
292 | |
293 // `Covariant` must be in front of modifiers. | |
294 int f55( | |
295 final | |
296 covariant /// 55: compile-time error | |
297 x) => 499; | |
298 | |
299 int f56(covariant final int x) => 499; | |
300 | |
301 // `Covariant` must be in front of modifiers. | |
302 int f57( | |
303 final | |
304 covariant /// 57: compile-time error | |
305 int | |
306 x) => 499; | |
307 | |
308 // `Covariant` on its own is just a parameter name. | |
309 int f58(covariant) => covariant; | |
310 } | |
311 | |
312 void use(x) {} | |
313 | |
314 main() { | |
315 x0 = 0; | |
316 use(x1); | |
317 x2 = 499; | |
318 use(x3); | |
319 use(x4); | |
320 x5 = 42; | |
321 x6 = 0; /// 06: continued | |
322 use(x7); | |
323 x8 = 11; | |
324 x9 = 12; | |
325 use(f10()); | |
326 use(f11()); | |
327 use(f12(2)); | |
328 use(f13(3)); | |
329 use(f14(3)); | |
330 use(f15(3)); | |
331 use(f16(3)); | |
332 use(f17(3)); | |
333 Expect.equals(123, f18(123)); | |
334 | |
335 A.x20 = 0; | |
336 use(A.x21); | |
337 use(A.x21b); | |
338 A.x22 = 499; | |
339 use(A.x23); | |
340 use(A.x24); | |
341 A.x25 = 42; | |
342 A.x26 = 0; /// 06: continued | |
eernst
2017/01/11 16:20:08
DBC, should this be `26: continued`?
floitsch
2017/01/11 18:02:33
Done.
| |
343 use(A.x27); | |
344 use(A.x27b); | |
345 A.x28 = 11; | |
346 A.x29 = 12; | |
347 use(A.f30()); | |
348 use(A.f31()); | |
349 use(A.f31b()); | |
350 use(A.f32(2)); | |
351 use(A.f33(3)); | |
352 use(A.f34(3)); | |
353 use(A.f35(3)); | |
354 use(A.f36(3)); | |
355 use(A.f37(3)); | |
356 Expect.equals(1234, A.f38(1234)); | |
357 | |
358 var b = new B(); | |
359 b.x40 = 0; | |
360 use(b.x41); | |
361 b.x42 = 499; | |
362 use(b.x43); | |
363 use(b.x44); | |
364 b.x45 = 42; | |
365 b.x46 = 0; /// 06: continued | |
eernst
2017/01/11 16:20:08
DBC, should this be `46: continued`?
floitsch
2017/01/11 18:02:33
Done.
| |
366 use(b.x47); | |
367 b.x48 = 11; | |
368 b.x49 = 12; | |
369 use(b.f50()); | |
370 use(b.f51()); | |
371 use(b.f52(2)); | |
372 use(b.f53(2)); | |
373 use(b.f54(3)); | |
374 use(b.f55(3)); | |
375 use(b.f56(3)); | |
376 use(b.f57(3)); | |
377 Expect.equals(12345, b.f58(12345)); | |
378 } | |
OLD | NEW |