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 | 4 |
5 import "package:expect/expect.dart"; | 5 import "package:expect/expect.dart"; |
6 | 6 |
7 abstract class Interface { | 7 abstract class Interface { |
8 final x; | 8 final x; |
9 } | 9 } |
10 | 10 |
11 abstract class Abstract implements Interface { | 11 abstract class Abstract implements Interface { |
12 String toString() => x.toString(); | 12 String toString() => x.toString(); |
13 } | 13 } |
14 | 14 |
15 // This class does not implement "x" either, but it is not marked | 15 // This class does not implement "x" either, but it is not marked |
16 // abstract. | 16 // abstract. |
17 class SubAbstract1 extends Abstract { } //# 01: static type warning | 17 class SubAbstract1 extends Abstract { } //# 01: static type warning |
18 | 18 |
19 // This class is implicitly abstract as it declares an abstract getter | 19 // This class is implicitly abstract as it declares an abstract getter |
20 // method. | 20 // method. |
21 class SubAbstract2 extends Abstract { | 21 class SubAbstract2 extends Abstract { |
22 get x; // Abstract. | 22 get x; // Abstract. |
23 } | 23 } |
24 | 24 |
25 // This class does not implement "x" either, but it is not marked | 25 // This class does not implement "x" either, but it is not marked |
26 // abstract. | 26 // abstract. |
27 class SubSubAbstract2 extends SubAbstract2 { } //# 04: static type warning | 27 class SubSubAbstract2 extends SubAbstract2 { } //# 04: static type warning |
28 | 28 |
29 class Concrete extends Abstract { | 29 class Concrete extends Abstract { |
30 get x => 7; | 30 get x => 7; |
31 } | 31 } |
32 | 32 |
33 class SubConcrete extends Concrete { | 33 class SubConcrete extends Concrete { |
34 final x; | 34 final x; |
35 SubConcrete(this.x); | 35 SubConcrete(this.x); |
36 } | 36 } |
37 | 37 |
38 void main() { | 38 void main() { |
39 var x = new Abstract(); //# 02: runtime error | 39 var x = new Abstract(); //# 02: runtime error |
40 var y = new SubAbstract1(); //# 01: continued | 40 var y = new SubAbstract1(); //# 01: continued |
41 var z = new SubAbstract2(); | 41 var z = new SubAbstract2(); |
42 var a = new SubSubAbstract2(); //# 04: continued | 42 var a = new SubSubAbstract2(); //# 04: continued |
43 Expect.equals(x, x); //# 02: continued | 43 Expect.equals(x, x); //# 02: continued |
44 Expect.equals('7', new Concrete().toString()); | 44 Expect.equals('7', new Concrete().toString()); |
45 Expect.equals('42', new SubConcrete(42).toString()); | 45 Expect.equals('42', new SubConcrete(42).toString()); |
46 Expect.equals('7', new SubConcrete(new Concrete()).toString()); | 46 Expect.equals('7', new SubConcrete(new Concrete()).toString()); |
47 } | 47 } |
OLD | NEW |