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) : b = x + 1, super(x); |
16 | 16 |
17 // Const constructor cannot call non-const super constructor. | 17 // Const constructor cannot call non-const super constructor. |
18 const B.zerofive() : b = 0, super(5); /// 01: compile-time error | 18 const B.zerofive() : b = 0, super(5); // /// 01: compile-time error |
19 } | 19 } |
20 | 20 |
21 class C extends A { | 21 class C extends A { |
22 C() : super(0); | 22 C() : super(0); |
23 // Implicit call to non-const constructor A(x). | 23 // Implicit call to non-const constructor A(x). |
24 const C.named(x); /// 02: compile-time error | 24 const C.named(x); // /// 02: compile-time error |
25 } | 25 } |
26 | 26 |
27 main() { | 27 main() { |
28 var b = new B.zerofive(); /// 01: continued | 28 var b = new B.zerofive(); // /// 01: continued |
29 var b1 = new B(0); | 29 var b1 = new B(0); |
30 var c = new C.named(""); /// 02: continued | 30 var c = new C.named(""); // /// 02: continued |
31 } | 31 } |
OLD | NEW |