| OLD | NEW |
| 1 // Copyright (c) 2011, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2011, 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 // Dart test program for constructors and initializers. | 4 // Dart test program for constructors and initializers. |
| 5 | 5 |
| 6 import "package:expect/expect.dart"; | 6 import "package:expect/expect.dart"; |
| 7 | 7 |
| 8 // Expect the initializer expressions E(i) to be evaluated | 8 // Expect the initializer expressions E(i) to be evaluated |
| 9 // in the order 1, 2, 3, ... | 9 // in the order 1, 2, 3, ... |
| 10 // Each expression must be evaluated exactly once. | 10 // Each expression must be evaluated exactly once. |
| 11 | 11 |
| 12 String trace = ""; | 12 String trace = ""; |
| 13 | 13 |
| 14 int E(int i) { | 14 int E(int i) { |
| 15 trace += "$i-"; | 15 trace += "$i-"; |
| 16 return i; | 16 return i; |
| 17 } | 17 } |
| 18 | 18 |
| 19 class A { | 19 class A { |
| 20 var a1; | 20 var a1; |
| 21 A(x, y) : a1 = E(3) { | 21 A(x, y) : a1 = E(3) { |
| 22 Expect.equals(1, x); | 22 Expect.equals(1, x); |
| 23 Expect.equals(2, y); | 23 Expect.equals(2, y); |
| 24 E(5); | 24 E(5); |
| 25 } | 25 } |
| 26 } | 26 } |
| 27 | 27 |
| 28 class B extends A { | 28 class B extends A { |
| 29 var b1; | 29 var b1; |
| 30 B(x) : super(E(1), E(2)), b1 = E(4) { | 30 B(x) |
| 31 : super(E(1), E(2)), |
| 32 b1 = E(4) { |
| 31 // Implicit super call to A's body happens here. | 33 // Implicit super call to A's body happens here. |
| 32 Expect.equals(4, b1); | 34 Expect.equals(4, b1); |
| 33 E(6); | 35 E(6); |
| 34 } | 36 } |
| 35 } | 37 } |
| 36 | 38 |
| 37 main() { | 39 main() { |
| 38 var b = new B(0); | 40 var b = new B(0); |
| 39 Expect.equals("1-2-3-4-5-6-", trace); | 41 Expect.equals("1-2-3-4-5-6-", trace); |
| 40 } | 42 } |
| OLD | NEW |