OLD | NEW |
1 // Copyright (c) 2017, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2017, 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 // The purpose of this test is to detect that closures in [LocalInitializer]s | 5 // The purpose of this test is to detect that closures in [LocalInitializer]s |
6 // and [FieldInitializer]s are properly converted. This test assumes that | 6 // and [FieldInitializer]s are properly converted. This test assumes that |
7 // [ArgumentExtractionForRedirecting] transformer was run before closure | 7 // [ArgumentExtractionForRedirecting] transformer was run before closure |
8 // conversion. It should introduce one [LocalInitializer] for each argument | 8 // conversion. It should introduce one [LocalInitializer] for each argument |
9 // passed to the redirecting constructor. If such argument contains a closure, | 9 // passed to the redirecting constructor. If such argument contains a closure, |
10 // it would appear in a [LocalInitializer]. The [FieldInitializer] example | 10 // it would appear in a [LocalInitializer]. The [FieldInitializer] example |
11 // requires no such elaboration. | 11 // requires no such elaboration. |
12 | 12 |
13 class X {} | 13 class X {} |
14 | 14 |
15 // Closure in field initializer. | 15 // Closure in field initializer. |
16 // | 16 // |
17 class A { | 17 class A { |
18 X foo; | 18 X foo; |
19 A(X i) : foo = ((() => i)()); | 19 A(X i) : foo = ((() => i)()); |
20 } | 20 } |
21 | 21 |
| 22 // Closure in super initializer. |
| 23 // |
| 24 class S extends A { |
| 25 S(X i) : super((() => i)()); |
| 26 } |
| 27 |
22 // Closure in local initializer. | 28 // Closure in local initializer. |
23 // | 29 // |
| 30 class S2 { |
| 31 X foo_li; |
| 32 S2(X foo) : foo_li = (() => foo)(); |
| 33 } |
| 34 |
| 35 // Closure in redirecting initializer. |
| 36 // |
24 class B { | 37 class B { |
25 X foo; | 38 X foo; |
26 B.named(X foo) {} | 39 B.named(X foo) {} |
27 B(X foo) : this.named((() => foo)()); | 40 B(X foo) : this.named((() => foo)()); |
28 } | 41 } |
29 | 42 |
30 main() { | 43 main() { |
31 A a = new A(new X()); | 44 A a = new A(new X()); |
32 a.foo; // To prevent dartanalyzer from marking [a] as unused. | 45 a.foo; // To prevent dartanalyzer from marking [a] as unused. |
33 B b = new B(new X()); | 46 B b = new B(new X()); |
34 b.foo; | 47 b.foo; |
| 48 S s = new S(new X()); |
| 49 s.foo; |
| 50 S2 s2 = new S2(new X()); |
| 51 s2.foo_li; |
35 } | 52 } |
OLD | NEW |