Chromium Code Reviews| 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 | |
| 28 // Closure in redirecting constructor. | |
| 29 // | |
| 30 class S2 { | |
| 31 X foo; | |
| 32 S2(this.foo); | |
| 33 | |
| 34 S2.wat(X i) : this((() => i)()); | |
|
Dmitry Stefantsov
2017/07/13 07:19:53
How this test case is different from the one for t
sjindel
2017/07/13 11:34:05
It wasn't -- I fixed this in patch set 2 by changi
| |
| 35 } | |
| 36 | |
| 22 // Closure in local initializer. | 37 // Closure in local initializer. |
| 23 // | 38 // |
| 24 class B { | 39 class B { |
| 25 X foo; | 40 X foo; |
| 26 B.named(X foo) {} | 41 B.named(X foo) {} |
| 27 B(X foo) : this.named((() => foo)()); | 42 B(X foo) : this.named((() => foo)()); |
| 28 } | 43 } |
| 29 | 44 |
| 30 main() { | 45 main() { |
| 31 A a = new A(new X()); | 46 A a = new A(new X()); |
| 32 a.foo; // To prevent dartanalyzer from marking [a] as unused. | 47 a.foo; // To prevent dartanalyzer from marking [a] as unused. |
| 33 B b = new B(new X()); | 48 B b = new B(new X()); |
| 34 b.foo; | 49 b.foo; |
| 50 S s = new S(new X()); | |
| 51 s.foo; | |
| 52 S2 s2 = new S2(new X()); | |
| 53 s2.foo; | |
| 35 } | 54 } |
| OLD | NEW |