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