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 // VMOptions=--constructor_name_check | |
5 | 4 |
6 class A { | 5 class A { |
7 // Constructor may not be static. | 6 // Constructor may not be static. |
8 static A(); /// 00: compile-time error | 7 static A(); /// 00: compile-time error |
9 | 8 |
10 // Factory may not be static. | 9 // Factory may not be static. |
11 static factory A() { return null; } /// 01: compile-time error | 10 static factory A() { return null; } /// 01: compile-time error |
12 | 11 |
13 // Named constructor may not conflict with names of methods and fields. | 12 // Named constructor may not conflict with names of methods and fields. |
14 var m; | 13 var m; |
15 A.m() { m = 0; } /// 04: compile-time error | 14 A.m() { m = 0; } /// 04: compile-time error |
16 | 15 |
17 set q(var value) { m = q; } | 16 set q(var value) { m = q; } // No name conflict with q=. |
18 A.q(); /// 05: compile-time error | 17 // The runtime error occurs because main calls new A() instead of new A.q(). |
| 18 A.q(); /// 05: runtime error |
19 | 19 |
20 A.foo() : m = 0; /// 06: compile-time error | 20 A.foo() : m = 0; /// 06: compile-time error |
21 int foo(int a, int b) => a + b * m; | 21 int foo(int a, int b) => a + b * m; |
22 } | 22 } |
23 | 23 |
24 main() { | 24 main() { |
25 new A(); | 25 new A(); |
26 } | 26 } |
OLD | NEW |