Chromium Code Reviews| Index: tests/language/covariant_test.dart |
| diff --git a/tests/language/covariant_test.dart b/tests/language/covariant_test.dart |
| new file mode 100644 |
| index 0000000000000000000000000000000000000000..5b2c60b181307f07c6ace64df69a13b18b508c93 |
| --- /dev/null |
| +++ b/tests/language/covariant_test.dart |
| @@ -0,0 +1,378 @@ |
| +// Copyright (c) 2017, the Dart project authors. Please see the AUTHORS file |
| +// for details. All rights reserved. Use of this source code is governed by a |
| +// BSD-style license that can be found in the LICENSE file. |
| + |
| +// Test that `covariant` can be parsed (and ignored) by |
| +// dart2js and the VM. |
| +// This test only checks for non-strong mode behavior. |
| +// |
| +// Generally, `covariant` should be ignored, when it is used in the right |
| +// places. |
| + |
| +import 'package:expect/expect.dart'; |
| + |
| +// Top level field may not have a covariant. |
| +// Would be considered a minor (acceptable) bug, if it was accepted here too. |
| +covariant /// 00: compile-time error |
| +int x0; |
| + |
| +// Getters may never have `covariant`. (Neither on the top-level nor as members) |
| +covariant /// 01: compile-time error |
| +int get x1 => 499; |
| + |
| +// Top level setters may not have a covariant. |
| +// Would be considered a minor (acceptable) bug, if it was accepted here too. |
| +void set x2( |
| + covariant /// 02: compile-time error |
| + int val) {} |
| + |
| +// Same as above, but with `covariant` in different positions. |
| +// The `covariant` is just wrong there. |
| + |
| +int |
| +covariant /// 03: compile-time error |
| +x3; |
| + |
| +int |
| +covariant /// 04: compile-time error |
| +get x4 => 499; |
| + |
| +void set x5( |
| + int |
| + covariant /// 05: compile-time error |
| + val) {} |
| + |
| + |
| +// Same without types. |
| + |
| +// Since `covariant` is a built-in identifier, it is not allowed here. |
| +covariant x6; /// 06: compile-time error |
| + |
| +// Getters may never have `covariant`. |
| +covariant /// 07: compile-time error |
| +get x7 => 499; |
| + |
| +// Top level setters may not have a covariant. |
| +// Would be considered a minor (acceptable) bug, if it was accepted here too. |
| +void set x8( |
| + covariant /// 08: compile-time error |
| + val) {} |
| + |
| +// If there is no type, then `covariant` is simply the parameter name: |
| +void set x9(covariant) {} |
| + |
| +// Covariant won't work on return types. |
| +covariant /// 10: compile-time error |
| +int f10() => 499; |
| + |
| +// Covariant won't work as a return type. |
| +covariant /// 11: compile-time error |
| +f11() => 499; |
| + |
| +// Covariant should not work on top-level methods. |
| +// It's a minor (acceptable) bug to not error out here. |
| +int f12( |
| + covariant /// 12: compile-time error |
| + int x) => 499; |
| + |
| +// `Covariant` must be in front of the types. |
| +int f13( |
| + int |
| + covariant /// 13: compile-time error |
| + x) => 499; |
| + |
| +// Covariant should not work on top-level methods. |
| +// It's a minor (acceptable) bug to not error out here. |
| +int f14( |
| + covariant /// 14: compile-time error |
| + final |
| + x) => 499; |
| + |
| +// `Covariant` must be in front of modifiers. |
| +int f15( |
| + final |
| + covariant /// 15: compile-time error |
| + x) => 499; |
| + |
| +// Covariant should not work on top-level methods. |
| +// It's a minor (acceptable) bug to not error out here. |
| +int f16( |
| + covariant /// 16: compile-time error |
| + final |
| + int |
| + x) => 499; |
| + |
| +// `Covariant` must be in front of modifiers. |
| +int f17( |
| + final |
| + covariant /// 17: compile-time error |
| + int |
| + x) => 499; |
| + |
| +// On its own, `covariant` is just a parameter name. |
| +int f18(covariant) => covariant; |
| + |
| +// All of the above as statics in a class. |
| +class A { |
| + // Static fields may not have a covariant. |
| + // Would be considered a minor (acceptable) bug, if it was accepted here too. |
| + static |
| + covariant /// 20: compile-time error |
| + int x20; |
| + |
| + // Getters may never have `covariant`. |
| + static |
| + covariant /// 21: compile-time error |
| + int get x21 => 499; |
| + |
| + // Getters may never have `covariant`. |
| + covariant /// 21b: compile-time error |
| + static |
| + int get x21b => 499; |
| + |
| + // Static setters may not have a covariant. |
| + // Would be considered a minor (acceptable) bug, if it was accepted here too. |
| + static void set x22( |
| + covariant /// 22: compile-time error |
| + int val) {} |
| + |
| + // Same as above, but with `covariant` in different positions. |
| + // The `covariant` is just wrong there. |
| + |
| + static int |
| + covariant /// 23: compile-time error |
| + x23; |
| + |
| + static int |
| + covariant /// 24: compile-time error |
| + get x24 => 499; |
| + |
| + static void set x25( |
| + int |
| + covariant /// 25: compile-time error |
| + val) {} |
| + |
| + // Since `covariant` is a built-in identifier, it is not allowed here. |
| + static covariant x26; /// 26: compile-time error |
| + |
| + // Getters may never have `covariant`. |
| + static |
| + covariant /// 27: compile-time error |
| + get x27 => 499; |
| + |
| + covariant /// 27b: compile-time error |
| + static |
| + get x27b => 499; |
| + |
| + // Static setters may not have a covariant. |
| + // Would be considered a minor (acceptable) bug, if it was accepted here too. |
| + static void set x28( |
| + covariant /// 28: compile-time error |
| + val) {} |
| + |
| + // If there is no type, then `covariant` is simply the parameter name: |
| + static void set x29(covariant) {} |
| + |
| + // Covariant won't work on return types. |
| + static |
| + covariant /// 30: compile-time error |
| + int f30() => 499; |
| + |
| + covariant /// 30b: compile-time error |
| + static |
| + int f30b() => 499; |
| + |
| + // Covariant won't work as a return type. |
| + static |
| + covariant /// 31: compile-time error |
| + f31() => 499; |
| + |
| + covariant /// 31b: compile-time error |
| + static |
| + f31b() => 499; |
| + |
| + // Covariant should not work on static methods. |
| + // It's a minor (acceptable) bug to not error out here. |
| + static int f32( |
| + covariant /// 32: compile-time error |
| + int x) => 499; |
| + |
| + // `Covariant` must be in front of the types. |
| + static int f33( |
| + int |
| + covariant /// 33: compile-time error |
| + x) => 499; |
| + |
| + // Covariant should not work on top-level methods. |
| + // It's a minor (acceptable) bug to not error out here. |
| + static int f34( |
| + covariant /// 34: compile-time error |
| + final |
| + x) => 499; |
| + |
| + // `Covariant` must be in front of modifiers. |
| + static int f35( |
| + final |
| + covariant /// 35: compile-time error |
| + x) => 499; |
| + |
| + // Covariant should not work on top-level methods. |
| + // It's a minor (acceptable) bug to not error out here. |
| + static int f36( |
| + covariant /// 36: compile-time error |
| + final |
| + int |
| + x) => 499; |
| + |
| + // `Covariant` must be in front of modifiers. |
| + static int f37( |
| + final |
| + covariant /// 37: compile-time error |
| + int |
| + x) => 499; |
| + |
| + // `Covariant` on its own is just a parameter name. |
| + static int f38(covariant) => covariant; |
| +} |
| + |
| +// All of the above as instance members in a class. |
| +class B { |
| + covariant int x40; |
| + |
| + // Getters may never have `covariant`. |
| + covariant /// 41: compile-time error |
| + int get x41 => 499; |
| + |
| + void set x42(covariant int val) {} |
| + |
| + // `covariant` in the wrong position. |
| + int |
| + covariant /// 43: compile-time error |
| + x43; |
| + |
| + // `covariant` in the wrong position. |
| + int |
| + covariant /// 44: compile-time error |
| + get x44 => 499; |
| + |
| + void set x45( |
| + int |
| + covariant /// 45: compile-time error |
| + val) {} |
| + |
| + // Since `covariant` is a built-in identifier, it is not allowed here. |
| + covariant x46; /// 46: compile-time error |
| + |
| + // Getters may never have `covariant`. |
| + covariant /// 47: compile-time error |
| + get x47 => 499; |
| + |
| + void set x48(covariant val) {} |
| + |
| + // If there is no type, then `covariant` is simply the parameter name: |
| + void set x49(covariant) {} |
| + |
| + // Covariant won't work on return types. |
| + covariant /// 50: compile-time error |
| + int f50() => 499; |
| + |
| + // Covariant won't work as a return type. |
| + covariant /// 51: compile-time error |
| + f51() => 499; |
| + |
| + int f52(covariant int x) => 499; |
| + |
| + // `Covariant` must be in front of the types. |
| + int f53( |
| + int |
| + covariant /// 53: compile-time error |
| + x) => 499; |
| + |
| + int f54(covariant final x) => 499; |
| + |
| + // `Covariant` must be in front of modifiers. |
| + int f55( |
| + final |
| + covariant /// 55: compile-time error |
| + x) => 499; |
| + |
| + int f56(covariant final int x) => 499; |
| + |
| + // `Covariant` must be in front of modifiers. |
| + int f57( |
| + final |
| + covariant /// 57: compile-time error |
| + int |
| + x) => 499; |
| + |
| + // `Covariant` on its own is just a parameter name. |
| + int f58(covariant) => covariant; |
| +} |
| + |
| +void use(x) {} |
| + |
| +main() { |
| + x0 = 0; |
| + use(x1); |
| + x2 = 499; |
| + use(x3); |
| + use(x4); |
| + x5 = 42; |
| + x6 = 0; /// 06: continued |
| + use(x7); |
| + x8 = 11; |
| + x9 = 12; |
| + use(f10()); |
| + use(f11()); |
| + use(f12(2)); |
| + use(f13(3)); |
| + use(f14(3)); |
| + use(f15(3)); |
| + use(f16(3)); |
| + use(f17(3)); |
| + Expect.equals(123, f18(123)); |
| + |
| + A.x20 = 0; |
| + use(A.x21); |
| + use(A.x21b); |
| + A.x22 = 499; |
| + use(A.x23); |
| + use(A.x24); |
| + A.x25 = 42; |
| + 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.
|
| + use(A.x27); |
| + use(A.x27b); |
| + A.x28 = 11; |
| + A.x29 = 12; |
| + use(A.f30()); |
| + use(A.f31()); |
| + use(A.f31b()); |
| + use(A.f32(2)); |
| + use(A.f33(3)); |
| + use(A.f34(3)); |
| + use(A.f35(3)); |
| + use(A.f36(3)); |
| + use(A.f37(3)); |
| + Expect.equals(1234, A.f38(1234)); |
| + |
| + var b = new B(); |
| + b.x40 = 0; |
| + use(b.x41); |
| + b.x42 = 499; |
| + use(b.x43); |
| + use(b.x44); |
| + b.x45 = 42; |
| + 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.
|
| + use(b.x47); |
| + b.x48 = 11; |
| + b.x49 = 12; |
| + use(b.f50()); |
| + use(b.f51()); |
| + use(b.f52(2)); |
| + use(b.f53(2)); |
| + use(b.f54(3)); |
| + use(b.f55(3)); |
| + use(b.f56(3)); |
| + use(b.f57(3)); |
| + Expect.equals(12345, b.f58(12345)); |
| +} |