| OLD | NEW |
| 1 // Copyright (c) 2015, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2015, 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 import "package:async_helper/async_helper.dart"; | 6 import "package:async_helper/async_helper.dart"; |
| 7 import 'compiler_helper.dart'; | 7 import 'compiler_helper.dart'; |
| 8 | 8 |
| 9 String TEST = r''' | 9 String SHOULD_NOT_BE_BOXED_TEST = r''' |
| 10 main() { | 10 main() { |
| 11 var a; | 11 var a; |
| 12 for (var i=0; i<10; i++) { | 12 for (var i=0; i<10; i++) { |
| 13 a = () => i; | 13 a = () => i; |
| 14 } | 14 } |
| 15 print(a()); | 15 print(a()); |
| 16 } | 16 } |
| 17 '''; | 17 '''; |
| 18 | 18 |
| 19 String NEGATIVE_TEST = r''' | 19 String SHOULD_BE_BOXED_TEST = r''' |
| 20 run(f) => f(); | 20 run(f) => f(); |
| 21 main() { | 21 main() { |
| 22 var a; | 22 var a; |
| 23 for (var i=0; i<10; run(() => i++)) { | 23 for (var i=0; i<10; run(() => i++)) { |
| 24 a = () => i; | 24 a = () => i; |
| 25 } | 25 } |
| 26 print(a()); | 26 print(a()); |
| 27 } | 27 } |
| 28 '''; | 28 '''; |
| 29 | 29 |
| 30 String ONLY_UPDATE_LOOP_VAR_TEST = r''' |
| 31 run(f) => f(); |
| 32 main() { |
| 33 var a; |
| 34 for (var i=0; i<10; run(() => i++)) { |
| 35 var b = 3; |
| 36 a = () => b = i; |
| 37 } |
| 38 print(a()); |
| 39 } |
| 40 '''; |
| 41 |
| 30 main() { | 42 main() { |
| 31 asyncTest(() => compileAll(TEST).then((generated) { | 43 asyncTest(() => compileAll(SHOULD_NOT_BE_BOXED_TEST).then((generated) { |
| 32 Expect.isTrue(generated.contains('main_closure(i)'), | 44 Expect.isTrue(generated.contains('main_closure(i)'), |
| 33 'for-loop variable was boxed'); | 45 'for-loop variable should not have been boxed'); |
| 34 })); | 46 })); |
| 35 asyncTest(() => compileAll(NEGATIVE_TEST).then((generated) { | 47 asyncTest(() => compileAll(SHOULD_BE_BOXED_TEST).then((generated) { |
| 36 Expect.isFalse(generated.contains('main_closure(i)'), | 48 Expect.isFalse(generated.contains('main_closure(i)'), |
| 37 'for-loop variable was not boxed'); | 49 'for-loop variable should have been boxed'); |
| 50 })); |
| 51 asyncTest(() => compileAll(ONLY_UPDATE_LOOP_VAR_TEST).then((generated) { |
| 52 Expect.isFalse(generated.contains('main_closure(i)'), |
| 53 'for-loop variable should have been boxed'); |
| 54 Expect.isFalse(generated.contains(', _box_0.b = 3,'), |
| 55 'non for-loop captured variable should not be updated in loop'); |
| 38 })); | 56 })); |
| 39 } | 57 } |
| OLD | NEW |