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"; | |
6 | |
7 class A { | 5 class A { |
8 num x; | 6 num x; |
9 A() : this.x = 0; | 7 A() : this.x = 0; |
10 | 8 |
11 void bar(){ | 9 void bar(){ |
12 // dart2js hoisted the this.x out of the loop, and missed that setX would | 10 // dart2js hoisted the this.x out of the loop, and missed that setX would |
13 // change the value. | 11 // change the value. |
14 for (int i = 1; i < 3; i++) { | 12 for (int i = 1; i < 3; i++) { |
15 setX(499); | 13 setX(499); |
16 foo(x); | 14 foo(x); |
17 break; | 15 break; |
18 } | 16 } |
19 } | 17 } |
20 setX(x) => this.x = x; | 18 setX(x) => this.x = x; |
21 } | 19 } |
22 | 20 |
23 var saved; | 21 var saved; |
24 foo(x) => saved = x; | 22 foo(x) => saved = x; |
25 | 23 |
26 main() { | 24 main() { |
27 A a = new A(); | 25 A a = new A(); |
28 for (int i = 0; i < 1; i++) { | 26 for (int i = 0; i < 1; i++) { |
29 a.bar(); | 27 a.bar(); |
30 } | 28 } |
31 Expect.equals(499, saved); | 29 Expect.equals(499, saved); |
32 } | 30 } |
OLD | NEW |