OLD | NEW |
1 // Copyright (c) 2014, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2014, 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 // Checks that abstract instance methods are correctly resolved. | 7 // Checks that abstract instance methods are correctly resolved. |
8 | 8 |
9 int get length => throw "error: top-level getter called"; | 9 int get length => throw "error: top-level getter called"; |
10 set height(x) { throw "error: top-level setter called"; } | 10 set height(x) { throw "error: top-level setter called"; } |
11 width() { throw "error: top-level function called"; } | 11 width() { throw "error: top-level function called"; } |
12 | 12 |
13 abstract class A { | 13 abstract class A { |
14 int get length; // Abstract instance getter. | 14 int get length; // Abstract instance getter. |
15 set height(x); // Abstract instance setter. | 15 set height(x); // Abstract instance setter. |
16 int width(); // Abstract instance method. | 16 int width(); // Abstract instance method. |
17 | 17 |
18 // Must resolve to non-abstract length getter in subclass. | 18 // Must resolve to non-abstract length getter in subclass. |
19 get useLength => length; | 19 get useLength => length; |
20 // Must resolve to non-abstract height setter in subclass. | 20 // Must resolve to non-abstract height setter in subclass. |
21 setHeight(x) => height = x; | 21 setHeight(x) => height = x; |
22 // Must resolve to non-abstract width() method in subclass. | 22 // Must resolve to non-abstract width() method in subclass. |
23 useWidth() => width(); | 23 useWidth() => width(); |
24 } | 24 } |
25 | 25 |
26 class A1 extends A { | 26 class A1 extends A { |
27 int length; // Implies a length getter. | 27 int length; // Implies a length getter. |
28 int height; // Implies a height setter. | 28 int height; // Implies a height setter. |
29 int width() => 345; | 29 int width() => 345; |
30 A1(this.length); | 30 A1(this.length); |
31 } | 31 } |
32 | 32 |
33 main() { | 33 main() { |
34 var a = new A1(123); | 34 var a = new A1(123); |
35 Expect.equals(123, a.useLength); | 35 Expect.equals(123, a.useLength); |
36 a.setHeight(234); | 36 a.setHeight(234); |
37 Expect.equals(234, a.height); | 37 Expect.equals(234, a.height); |
38 Expect.equals(345, a.useWidth()); | 38 Expect.equals(345, a.useWidth()); |
39 print([a.useLength, a.height, a.useWidth()]); | 39 print([a.useLength, a.height, a.useWidth()]); |
40 } | 40 } |
41 | 41 |
OLD | NEW |