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