Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(112)

Side by Side Diff: tests/language/covariant_test.dart

Issue 2629113002: Add a few more tests. (Closed)
Patch Set: Update status file. Created 3 years, 11 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « no previous file | tests/language/language.status » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2017, the Dart project authors. Please see the AUTHORS file 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 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 4
5 // Test that `covariant` can be parsed (and ignored) by 5 // Test that `covariant` can be parsed (and ignored) by
6 // dart2js and the VM. 6 // dart2js and the VM.
7 // This test only checks for non-strong mode behavior. 7 // This test only checks for non-strong mode behavior.
8 // 8 //
9 // Generally, `covariant` should be ignored, when it is used in the right 9 // Generally, `covariant` should be ignored, when it is used in the right
10 // places. 10 // places.
11 11
12 import 'package:expect/expect.dart'; 12 import 'package:expect/expect.dart';
13 13
14 // Top level field may not have a covariant. 14 // Top level field may not have a covariant.
15 // Would be considered a minor (acceptable) bug, if it was accepted here too. 15 // Would be considered a minor (acceptable) bug, if it was accepted here too.
16 covariant /// 00: compile-time error 16 covariant /// 00: compile-time error
17 int x0; 17 int x0;
18 18
19 covariant int covariant; /// 00b: compile-time error
20
21 int covariant; /// 00c: ok
22
19 // Getters may never have `covariant`. (Neither on the top-level nor as members) 23 // Getters may never have `covariant`. (Neither on the top-level nor as members)
20 covariant /// 01: compile-time error 24 covariant /// 01: compile-time error
21 int get x1 => 499; 25 int get x1 => 499;
22 26
23 // Top level setters may not have a covariant. 27 // Top level setters may not have a covariant.
24 // Would be considered a minor (acceptable) bug, if it was accepted here too. 28 // Would be considered a minor (acceptable) bug, if it was accepted here too.
25 void set x2( 29 void set x2(
26 covariant /// 02: compile-time error 30 covariant /// 02: compile-time error
27 int val) {} 31 int val) {}
28 32
(...skipping 12 matching lines...) Expand all
41 int 45 int
42 covariant /// 05: compile-time error 46 covariant /// 05: compile-time error
43 val) {} 47 val) {}
44 48
45 49
46 // Same without types. 50 // Same without types.
47 51
48 // Since `covariant` is a built-in identifier, it is not allowed here. 52 // Since `covariant` is a built-in identifier, it is not allowed here.
49 covariant x6; /// 06: compile-time error 53 covariant x6; /// 06: compile-time error
50 54
55 covariant covariant; /// 06b: compile-time error
56
51 // Getters may never have `covariant`. 57 // Getters may never have `covariant`.
52 covariant /// 07: compile-time error 58 covariant /// 07: compile-time error
53 get x7 => 499; 59 get x7 => 499;
54 60
55 // Top level setters may not have a covariant. 61 // Top level setters may not have a covariant.
56 // Would be considered a minor (acceptable) bug, if it was accepted here too. 62 // Would be considered a minor (acceptable) bug, if it was accepted here too.
57 void set x8( 63 void set x8(
58 covariant /// 08: compile-time error 64 covariant /// 08: compile-time error
59 val) {} 65 val) {}
60 66
(...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after
105 // `Covariant` must be in front of modifiers. 111 // `Covariant` must be in front of modifiers.
106 int f17( 112 int f17(
107 final 113 final
108 covariant /// 17: compile-time error 114 covariant /// 17: compile-time error
109 int 115 int
110 x) => 499; 116 x) => 499;
111 117
112 // On its own, `covariant` is just a parameter name. 118 // On its own, `covariant` is just a parameter name.
113 int f18(covariant) => covariant; 119 int f18(covariant) => covariant;
114 120
121 covariant; /// 19: compile-time error
122
115 // All of the above as statics in a class. 123 // All of the above as statics in a class.
116 class A { 124 class A {
117 // Static fields may not have a covariant. 125 // Static fields may not have a covariant.
118 // Would be considered a minor (acceptable) bug, if it was accepted here too. 126 // Would be considered a minor (acceptable) bug, if it was accepted here too.
119 static 127 static
120 covariant /// 20: compile-time error 128 covariant /// 20: compile-time error
121 int x20; 129 int x20;
122 130
131 static covariant int covariant /// 20b: compile-time error
132
133 static int covariant; /// 20c: ok
134
123 // Getters may never have `covariant`. 135 // Getters may never have `covariant`.
124 static 136 static
125 covariant /// 21: compile-time error 137 covariant /// 21: compile-time error
126 int get x21 => 499; 138 int get x21 => 499;
127 139
128 // Getters may never have `covariant`. 140 // Getters may never have `covariant`.
129 covariant /// 21b: compile-time error 141 covariant /// 21b: compile-time error
130 static 142 static
131 int get x21b => 499; 143 int get x21b => 499;
132 144
(...skipping 14 matching lines...) Expand all
147 covariant /// 24: compile-time error 159 covariant /// 24: compile-time error
148 get x24 => 499; 160 get x24 => 499;
149 161
150 static void set x25( 162 static void set x25(
151 int 163 int
152 covariant /// 25: compile-time error 164 covariant /// 25: compile-time error
153 val) {} 165 val) {}
154 166
155 // Since `covariant` is a built-in identifier, it is not allowed here. 167 // Since `covariant` is a built-in identifier, it is not allowed here.
156 static covariant x26; /// 26: compile-time error 168 static covariant x26; /// 26: compile-time error
169 static covariant covariant; /// 26b: compile-time error
157 170
158 // Getters may never have `covariant`. 171 // Getters may never have `covariant`.
159 static 172 static
160 covariant /// 27: compile-time error 173 covariant /// 27: compile-time error
161 get x27 => 499; 174 get x27 => 499;
162 175
163 covariant /// 27b: compile-time error 176 covariant /// 27b: compile-time error
164 static 177 static
165 get x27b => 499; 178 get x27b => 499;
166 179
(...skipping 59 matching lines...) Expand 10 before | Expand all | Expand 10 after
226 239
227 // `Covariant` must be in front of modifiers. 240 // `Covariant` must be in front of modifiers.
228 static int f37( 241 static int f37(
229 final 242 final
230 covariant /// 37: compile-time error 243 covariant /// 37: compile-time error
231 int 244 int
232 x) => 499; 245 x) => 499;
233 246
234 // `Covariant` on its own is just a parameter name. 247 // `Covariant` on its own is just a parameter name.
235 static int f38(covariant) => covariant; 248 static int f38(covariant) => covariant;
249
250 static covariant; /// 39: compile-time error
251
236 } 252 }
237 253
238 // All of the above as instance members in a class. 254 // All of the above as instance members in a class.
239 class B { 255 class B {
240 covariant int x40; 256 covariant /// 40: ok
257 int x40;
258
259 covariant int covariant; /// 40b: ok
260
261 int covariant; /// 40c: ok
241 262
242 // Getters may never have `covariant`. 263 // Getters may never have `covariant`.
243 covariant /// 41: compile-time error 264 covariant /// 41: compile-time error
244 int get x41 => 499; 265 int get x41 => 499;
245 266
246 void set x42(covariant int val) {} 267 void set x42(
268 covariant /// 42: ok
269 int val) {}
247 270
248 // `covariant` in the wrong position. 271 // `covariant` in the wrong position.
249 int 272 int
250 covariant /// 43: compile-time error 273 covariant /// 43: compile-time error
251 x43; 274 x43;
252 275
253 // `covariant` in the wrong position. 276 // `covariant` in the wrong position.
254 int 277 int
255 covariant /// 44: compile-time error 278 covariant /// 44: compile-time error
256 get x44 => 499; 279 get x44 => 499;
257 280
258 void set x45( 281 void set x45(
259 int 282 int
260 covariant /// 45: compile-time error 283 covariant /// 45: compile-time error
261 val) {} 284 val) {}
262 285
263 // Since `covariant` is a built-in identifier, it is not allowed here. 286 // Since `covariant` is a built-in identifier, it is not allowed here.
264 covariant x46; /// 46: compile-time error 287 covariant x46; /// 46: compile-time error
288 covariant covariant; /// 46b: compile-time error
265 289
266 // Getters may never have `covariant`. 290 // Getters may never have `covariant`.
267 covariant /// 47: compile-time error 291 covariant /// 47: compile-time error
268 get x47 => 499; 292 get x47 => 499;
269 293
270 void set x48(covariant val) {} 294 void set x48(
295 covariant /// 48: ok
296 val) {}
271 297
272 // If there is no type, then `covariant` is simply the parameter name: 298 // If there is no type, then `covariant` is simply the parameter name:
273 void set x49(covariant) {} 299 void set x49(covariant) {}
274 300
275 // Covariant won't work on return types. 301 // Covariant won't work on return types.
276 covariant /// 50: compile-time error 302 covariant /// 50: compile-time error
277 int f50() => 499; 303 int f50() => 499;
278 304
279 // Covariant won't work as a return type. 305 // Covariant won't work as a return type.
280 covariant /// 51: compile-time error 306 covariant /// 51: compile-time error
281 f51() => 499; 307 f51() => 499;
282 308
283 int f52(covariant int x) => 499; 309 int f52(
310 covariant /// 52: ok
311 int x) => 499;
284 312
285 // `Covariant` must be in front of the types. 313 // `Covariant` must be in front of the types.
286 int f53( 314 int f53(
287 int 315 int
288 covariant /// 53: compile-time error 316 covariant /// 53: compile-time error
289 x) => 499; 317 x) => 499;
290 318
291 int f54(covariant final x) => 499; 319 int f54(
320 covariant /// 54: ok
321 final x) => 499;
292 322
293 // `Covariant` must be in front of modifiers. 323 // `Covariant` must be in front of modifiers.
294 int f55( 324 int f55(
295 final 325 final
296 covariant /// 55: compile-time error 326 covariant /// 55: compile-time error
297 x) => 499; 327 x) => 499;
298 328
299 int f56(covariant final int x) => 499; 329 int f56(
330 covariant /// 56: ok
331 final int x) => 499;
300 332
301 // `Covariant` must be in front of modifiers. 333 // `Covariant` must be in front of modifiers.
302 int f57( 334 int f57(
303 final 335 final
304 covariant /// 57: compile-time error 336 covariant /// 57: compile-time error
305 int 337 int
306 x) => 499; 338 x) => 499;
307 339
308 // `Covariant` on its own is just a parameter name. 340 // `Covariant` on its own is just a parameter name.
309 int f58(covariant) => covariant; 341 int f58(covariant) => covariant;
342
343 covariant; /// 59: compile-time error
310 } 344 }
311 345
312 void use(x) {} 346 void use(x) {}
313 347
314 main() { 348 main() {
315 x0 = 0; 349 x0 = 0;
350 covariant = 0; /// 00b: continued
351 covariant = 0; /// 00c: continued
316 use(x1); 352 use(x1);
317 x2 = 499; 353 x2 = 499;
318 use(x3); 354 use(x3);
319 use(x4); 355 use(x4);
320 x5 = 42; 356 x5 = 42;
321 x6 = 0; /// 06: continued 357 x6 = 0; /// 06: continued
358 covariant = 0; /// 06b: continued
322 use(x7); 359 use(x7);
323 x8 = 11; 360 x8 = 11;
324 x9 = 12; 361 x9 = 12;
325 use(f10()); 362 use(f10());
326 use(f11()); 363 use(f11());
327 use(f12(2)); 364 use(f12(2));
328 use(f13(3)); 365 use(f13(3));
329 use(f14(3)); 366 use(f14(3));
330 use(f15(3)); 367 use(f15(3));
331 use(f16(3)); 368 use(f16(3));
332 use(f17(3)); 369 use(f17(3));
333 Expect.equals(123, f18(123)); 370 Expect.equals(123, f18(123));
371 use(covariant); /// 19: continued
334 372
335 A.x20 = 0; 373 A.x20 = 0;
374 A.covariant = 0; /// 20b: continued
375 A.covariant = 0; /// 20c: continued
336 use(A.x21); 376 use(A.x21);
337 use(A.x21b); 377 use(A.x21b);
338 A.x22 = 499; 378 A.x22 = 499;
339 use(A.x23); 379 use(A.x23);
340 use(A.x24); 380 use(A.x24);
341 A.x25 = 42; 381 A.x25 = 42;
342 A.x26 = 0; /// 26: continued 382 A.x26 = 0; /// 26: continued
383 A.covariant = 0; /// 26b: continued
343 use(A.x27); 384 use(A.x27);
344 use(A.x27b); 385 use(A.x27b);
345 A.x28 = 11; 386 A.x28 = 11;
346 A.x29 = 12; 387 A.x29 = 12;
347 use(A.f30()); 388 use(A.f30());
348 use(A.f31()); 389 use(A.f31());
349 use(A.f31b()); 390 use(A.f31b());
350 use(A.f32(2)); 391 use(A.f32(2));
351 use(A.f33(3)); 392 use(A.f33(3));
352 use(A.f34(3)); 393 use(A.f34(3));
353 use(A.f35(3)); 394 use(A.f35(3));
354 use(A.f36(3)); 395 use(A.f36(3));
355 use(A.f37(3)); 396 use(A.f37(3));
356 Expect.equals(1234, A.f38(1234)); 397 Expect.equals(1234, A.f38(1234));
398 use(A.covariant); /// 39: continued
357 399
358 var b = new B(); 400 var b = new B();
359 b.x40 = 0; 401 b.x40 = 0;
402 b.covariant = 0; /// 40b: continued
403 b.covariant = 0; /// 40c: continued
360 use(b.x41); 404 use(b.x41);
361 b.x42 = 499; 405 b.x42 = 499;
362 use(b.x43); 406 use(b.x43);
363 use(b.x44); 407 use(b.x44);
364 b.x45 = 42; 408 b.x45 = 42;
365 b.x46 = 0; /// 46: continued 409 b.x46 = 0; /// 46: continued
410 b.covariant = 0; /// 46b: continued
366 use(b.x47); 411 use(b.x47);
367 b.x48 = 11; 412 b.x48 = 11;
368 b.x49 = 12; 413 b.x49 = 12;
369 use(b.f50()); 414 use(b.f50());
370 use(b.f51()); 415 use(b.f51());
371 use(b.f52(2)); 416 use(b.f52(2));
372 use(b.f53(2)); 417 use(b.f53(2));
373 use(b.f54(3)); 418 use(b.f54(3));
374 use(b.f55(3)); 419 use(b.f55(3));
375 use(b.f56(3)); 420 use(b.f56(3));
376 use(b.f57(3)); 421 use(b.f57(3));
377 Expect.equals(12345, b.f58(12345)); 422 Expect.equals(12345, b.f58(12345));
423 use(B.covariant); /// 59: continued
378 } 424 }
OLDNEW
« no previous file with comments | « no previous file | tests/language/language.status » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698