OLD | NEW |
1 // Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2012, 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 // Dart test checking that static/instance field shadowing do not conflict. | 4 // Dart test checking that static/instance field shadowing do not conflict. |
5 | 5 |
| 6 import 'package:expect/expect.dart' show Expect; |
| 7 |
6 // Test that certain interfaces/classes are blacklisted from being | 8 // Test that certain interfaces/classes are blacklisted from being |
7 // implemented or extended. | 9 // implemented or extended. |
8 | 10 |
9 // bool. | 11 class MyBool |
10 class MyBool implements bool {} // //# 01: compile-time error | 12 extends bool //# 01a: compile-time error |
11 abstract class MyBoolInterface implements bool default F { // //# 02: compile-ti
me error | 13 implements bool //# 01b: compile-time error |
12 MyBoolInterface(); // //# 02: continued | 14 extends Object with bool //# 01c: compile-time error |
13 } // //# 02: continued | 15 { |
14 | 16 factory MyBool() => throw "bad"; |
15 // num. | |
16 class MyNum implements num {} // //# 03: compile-time error | |
17 abstract class MyNumInterface implements num default F { // //# 04: compile-ti
me error | |
18 MyNumInterface(); // //# 04: continued | |
19 } // //# 04: continued | |
20 | |
21 // int. | |
22 class MyInt implements int {} // //# 05: compile-time error | |
23 abstract class MyIntInterface implements int default F { // //# 06: compile-ti
me error | |
24 MyIntInterface(); // //# 06: continued | |
25 } // //# 06: continued | |
26 | |
27 // double. | |
28 class MyDouble implements double {} // //# 07: compile-time e
rror | |
29 abstract class MyDoubleInterface implements double default F { // //# 08: compil
e-time error | |
30 MyDoubleInterface(); // //# 08: continued | |
31 } // //# 08: continued | |
32 | |
33 // String. | |
34 class MyString implements String {} // //# 09: compile-time e
rror | |
35 abstract class MyStringInterface implements String default F { // //# 10: compil
e-time error | |
36 MyStringInterface(); // //# 10: continued | |
37 } // //# 10: continued | |
38 | |
39 // Function. | |
40 class MyFunction implements Function {} | |
41 | |
42 class MyOtherFunction extends Function {} | |
43 abstract class MyFunctionInterface implements Function default F { // //# 12: co
mpile-time error | |
44 MyFunctionInterface(); // //# 12: continued | |
45 } // //# 12: continued | |
46 | |
47 // dynamic. | |
48 class MyDynamic implements dynamic {} // //# 13: compile-tim
e error | |
49 abstract class MyDynamicInterface implements dynamic default F { // //# 14: com
pile-time error | |
50 MyDynamicInterface(); // //# 14: continued | |
51 } // //# 14: continued | |
52 | |
53 class F { | |
54 factory MyBoolInterface() { return null; } // //# 02: continued | |
55 factory MyNumInterface() { return null; } // //# 04: continued | |
56 factory MyIntInterface() { return null; } // //# 06: continued | |
57 factory MyDoubleInterface() { return null; } // //# 08: continued | |
58 factory MyStringInterface() { return null; } // //# 10: continued | |
59 factory MyFunctionInterface() { return null; } // //# 12: continued | |
60 factory MyDynamicInterface() { return null; } // //# 14: continued | |
61 } | 17 } |
62 | 18 |
| 19 abstract class MyBoolInterface |
| 20 extends bool //# 02a: compile-time error |
| 21 implements bool //# 02b: compile-time error |
| 22 extends Object with bool //# 02c: compile-time error |
| 23 { |
| 24 factory MyBoolInterface() => throw "bad"; |
| 25 } |
| 26 |
| 27 class MyNum |
| 28 extends num //# 03a: compile-time error |
| 29 implements num //# 03b: compile-time error |
| 30 extends Object with num //# 03c: compile-time error |
| 31 { |
| 32 factory MyNum() => throw "bad"; |
| 33 } |
| 34 |
| 35 abstract class MyNumInterface |
| 36 extends num //# 04a: compile-time error |
| 37 implements num //# 04b: compile-time error |
| 38 extends Object with num //# 04c: compile-time error |
| 39 { |
| 40 factory MyNumInterface() => throw "bad"; |
| 41 } |
| 42 |
| 43 class MyInt |
| 44 extends int //# 05a: compile-time error |
| 45 implements int //# 05b: compile-time error |
| 46 extends Object with int //# 05c: compile-time error |
| 47 { |
| 48 factory MyInt() => throw "bad"; |
| 49 } |
| 50 |
| 51 abstract class MyIntInterface |
| 52 extends int //# 06a: compile-time error |
| 53 implements int //# 06b: compile-time error |
| 54 extends Object with int //# 06c: compile-time error |
| 55 { |
| 56 factory MyIntInterface() => throw "bad"; |
| 57 } |
| 58 |
| 59 class MyDouble |
| 60 extends double //# 07a: compile-time error |
| 61 implements double //# 07b: compile-time error |
| 62 extends Object with double //# 07c: compile-time error |
| 63 { |
| 64 factory MyDouble() => throw "bad"; |
| 65 } |
| 66 |
| 67 abstract class MyDoubleInterface |
| 68 extends double //# 08a: compile-time error |
| 69 implements double //# 08b: compile-time error |
| 70 extends Object with double //# 08c: compile-time error |
| 71 { |
| 72 factory MyDoubleInterface() => throw "bad"; |
| 73 } |
| 74 |
| 75 class MyString |
| 76 extends String //# 09a: compile-time error |
| 77 implements String //# 09b: compile-time error |
| 78 extends Object with String //# 09c: compile-time error |
| 79 { |
| 80 factory MyString() => throw "bad"; |
| 81 } |
| 82 |
| 83 abstract class MyStringInterface |
| 84 extends String //# 10a: compile-time error |
| 85 implements String //# 10b: compile-time error |
| 86 extends Object with String //# 10c: compile-time error |
| 87 { |
| 88 factory MyStringInterface() => throw "bad"; |
| 89 } |
| 90 |
| 91 class MyFunction implements Function { |
| 92 factory MyFunction() => throw "bad"; |
| 93 } |
| 94 |
| 95 class MyOtherFunction extends Function { |
| 96 factory MyOtherFunction() => throw "bad"; |
| 97 } |
| 98 |
| 99 abstract class MyFunctionInterface implements Function { |
| 100 factory MyFunctionInterface() => throw "bad"; |
| 101 } |
| 102 |
| 103 class MyDynamic |
| 104 extends dynamic //# 13a: compile-time error |
| 105 implements dynamic //# 13b: compile-time error |
| 106 extends Object with dynamic //# 13c: compile-time error |
| 107 { |
| 108 factory MyDynamic() => throw "bad"; |
| 109 } |
| 110 |
| 111 abstract class MyDynamicInterface |
| 112 extends dynamic //# 14a: compile-time error |
| 113 implements dynamic //# 14b: compile-time error |
| 114 extends Object with dynamic //# 14c: compile-time error |
| 115 { |
| 116 factory MyDynamicInterface() => throw "bad"; |
| 117 } |
| 118 |
| 119 bool isBadString(e) => identical("bad", e); |
| 120 |
63 main() { | 121 main() { |
64 new MyBool(); // //# 01: continued | 122 Expect.throws(() => new MyBool(), isBadString); |
65 new MyBoolInterface(); // //# 02: continued | 123 Expect.throws(() => new MyBoolInterface(), isBadString); |
66 new MyNum(); // //# 03: continued | 124 Expect.throws(() => new MyNum(), isBadString); |
67 new MyNumInterface(); // //# 04: continued | 125 Expect.throws(() => new MyNumInterface(), isBadString); |
68 new MyInt(); // //# 05: continued | 126 Expect.throws(() => new MyInt(), isBadString); |
69 new MyIntInterface(); // //# 06: continued | 127 Expect.throws(() => new MyIntInterface(), isBadString); |
70 new MyDouble(); // //# 07: continued | 128 Expect.throws(() => new MyDouble(), isBadString); |
71 new MyDoubleInterface(); // //# 08: continued | 129 Expect.throws(() => new MyDoubleInterface(), isBadString); |
72 new MyString(); // //# 09: continued | 130 Expect.throws(() => new MyString(), isBadString); |
73 new MyStringInterface(); // //# 10: continued | 131 Expect.throws(() => new MyStringInterface(), isBadString); |
74 new MyFunction(); | 132 Expect.throws(() => new MyFunction(), isBadString); |
75 new MyOtherFunction(); | 133 Expect.throws(() => new MyOtherFunction(), isBadString); |
76 new MyFunctionInterface(); //# 12: continued | 134 Expect.throws(() => new MyFunctionInterface(), isBadString); |
77 new MyDynamic(); // //# 13: continued | 135 Expect.throws(() => new MyDynamic(), isBadString); |
78 new MyDynamicInterface(); // //# 14: continued | 136 Expect.throws(() => new MyDynamicInterface(), isBadString); |
79 } | 137 } |
OLD | NEW |