OLD | NEW |
1 // Copyright (c) 2013, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2013, 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 class A { | 7 class A { |
8 final a; | 8 final a; |
9 A(this.a); // Not const. | 9 A(this.a); // Not const. |
10 const A.five() : a = 5; | 10 const A.five() : a = 5; |
11 } | 11 } |
12 | 12 |
13 class B extends A { | 13 class B extends A { |
14 final b; | 14 final b; |
15 B(x) : b = x + 1, super(x); | 15 B(x) |
| 16 : b = x + 1, |
| 17 super(x); |
16 | 18 |
17 // Const constructor cannot call non-const super constructor. | 19 // Const constructor cannot call non-const super constructor. |
18 const B.zerofive() : b = 0, super(5); // //# 01: compile-time error | 20 const B.zerofive() : b = 0, super(5); // //# 01: compile-time error |
19 } | 21 } |
20 | 22 |
21 class C extends A { | 23 class C extends A { |
22 C() : super(0); | 24 C() : super(0); |
23 // Implicit call to non-const constructor A(x). | 25 // Implicit call to non-const constructor A(x). |
24 const C.named(x); // //# 02: compile-time error | 26 const C.named(x); // //# 02: compile-time error |
25 } | 27 } |
26 | 28 |
27 main() { | 29 main() { |
28 var b = new B.zerofive(); // //# 01: continued | 30 var b = new B.zerofive(); // //# 01: continued |
29 var b1 = new B(0); | 31 var b1 = new B(0); |
30 var c = new C.named(""); // //# 02: continued | 32 var c = new C.named(""); // //# 02: continued |
31 } | 33 } |
OLD | NEW |