OLD | NEW |
| (Empty) |
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 | |
3 // BSD-style license that can be found in the LICENSE file. | |
4 | |
5 class BaseClass { | |
6 var foo; | |
7 BaseClass() { foo = 0; } | |
8 toString() => "BaseClass"; | |
9 } | |
10 | |
11 /** | |
12 * This class declaration causes an intentional type warning as it | |
13 * isn't marked abstract. It is abstract because it doesn't | |
14 * "implement" the field foo. | |
15 */ | |
16 class ImplementsClass implements BaseClass { | |
17 ImplementsClass() {} | |
18 } | |
19 | |
20 interface ExtendsClass extends BaseClass {} | |
21 | |
22 /** | |
23 * This class declaration causes an intentional type warning as it | |
24 * isn't marked abstract. It is abstract because it doesn't | |
25 * "implement" the field foo. | |
26 */ | |
27 class ImplementsExtendsClass implements ExtendsClass { | |
28 ImplementsExtendsClass() {} | |
29 } | |
30 | |
31 main() { | |
32 ImplementsClass c1 = new ImplementsClass(); | |
33 ImplementsExtendsClass c2 = new ImplementsExtendsClass(); | |
34 try { | |
35 c1.foo; | |
36 Expect.fail('expected a NoSuchMethodException'); | |
37 } catch (NoSuchMethodException ex) { | |
38 // Expected error. | |
39 } | |
40 try { | |
41 c2.foo; | |
42 Expect.fail('expected a NoSuchMethodException'); | |
43 } catch (NoSuchMethodException ex) { | |
44 // Expected error. | |
45 } | |
46 Expect.equals(true, c1 is BaseClass); | |
47 Expect.equals(true, c1 is !ExtendsClass); | |
48 Expect.equals(true, c2 is BaseClass); | |
49 Expect.equals(true, c2 is ExtendsClass); | |
50 Expect.equals(true, c2 is !ImplementsClass); | |
51 Expect.equals("BaseClass", "${new BaseClass()}"); | |
52 | |
53 // Verify we don't inherit toString from BaseClass | |
54 Expect.notEquals("BaseClass", "${c1}"); | |
55 Expect.notEquals("BaseClass", "${c2}"); | |
56 } | |
OLD | NEW |