| 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 A { | 7 abstract class A { |
| 8 factory A(int x, int y) = B; | 8 factory A(int x, int y) = B; |
| 9 } | 9 } |
| 10 | 10 |
| 11 abstract class X { | 11 abstract class X { |
| 12 factory X(int x, int y) = B.X; | 12 factory X(int x, int y) = B.X; |
| 13 } | 13 } |
| 14 | 14 |
| 15 class XImpl implements X { | 15 class XImpl implements X { |
| 16 final int x; | 16 final int x; |
| 17 final int y; | 17 final int y; |
| 18 XImpl(this.x, this.y); | 18 XImpl(this.x, this.y); |
| 19 } | 19 } |
| 20 | 20 |
| 21 class B implements A { | 21 class B implements A { |
| 22 final int x; | 22 final int x; |
| 23 final int y; | 23 final int y; |
| 24 | 24 |
| 25 B(this.x, this.y); | 25 B(this.x, this.y); |
| 26 // This factory will never be invoked. | 26 // This factory will never be invoked. |
| 27 // TODO(ahe): Is this a compile time error? | 27 // TODO(ahe): Is this a compile time error? |
| 28 factory B.A(int a, int b) { return new B(0, 0); } | 28 factory B.A(int a, int b) { |
| 29 return new B(0, 0); |
| 30 } |
| 29 | 31 |
| 30 factory B.X(int a, int b) { return new XImpl(a * 10, b * 10); } | 32 factory B.X(int a, int b) { |
| 33 return new XImpl(a * 10, b * 10); |
| 34 } |
| 31 } | 35 } |
| 32 | 36 |
| 33 main() { | 37 main() { |
| 34 var a = new A(1, 2); | 38 var a = new A(1, 2); |
| 35 // Check that constructor B is invoked and not factory B.A. | 39 // Check that constructor B is invoked and not factory B.A. |
| 36 Expect.equals(1, a.x); | 40 Expect.equals(1, a.x); |
| 37 Expect.equals(2, a.y); | 41 Expect.equals(2, a.y); |
| 38 | 42 |
| 39 var x = new X(11, 22); // //# 00: dynamic type error | 43 var x = new X(11, 22); // //# 00: dynamic type error |
| 40 // Check that factory is invoked. | 44 // Check that factory is invoked. |
| 41 Expect.equals(110, x.x); // //# 00: continued | 45 Expect.equals(110, x.x); // //# 00: continued |
| 42 Expect.equals(220, x.y); // //# 00: continued | 46 Expect.equals(220, x.y); // //# 00: continued |
| 43 } | 47 } |
| OLD | NEW |