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 // Test that free variables aren't mixed between capturing and non-capturing | 5 // Test that free variables aren't mixed between capturing and non-capturing |
6 // closures. | 6 // closures. |
7 | 7 |
8 /*mutateInClosure:box=(box0 which holds [localVar])*/ | 8 /*element: mutateInClosure:box=(box0 which holds [localVar])*/ |
9 mutateInClosure() { | 9 mutateInClosure() { |
10 var /*boxed*/ localVar; | 10 var /*boxed*/ localVar; |
11 /*free=[box0,localVar]*/ () { | 11 /*free=[box0,localVar]*/ () { |
12 localVar = 42; | 12 localVar = 42; |
13 }; | 13 }; |
14 /**/ () { | 14 /**/ () { |
15 // Use nothing. | 15 // Use nothing. |
16 }; | 16 }; |
17 return localVar; | 17 return localVar; |
18 } | 18 } |
19 | 19 |
20 /*mutateOutsideClosure:box=(box0 which holds [localVar])*/ | 20 /*element: mutateOutsideClosure:box=(box0 which holds [localVar])*/ |
21 mutateOutsideClosure() { | 21 mutateOutsideClosure() { |
22 var /*boxed*/ localVar; | 22 var /*boxed*/ localVar; |
23 /*free=[box0,localVar]*/ () { | 23 /*free=[box0,localVar]*/ () { |
24 print(localVar); | 24 print(localVar); |
25 }; | 25 }; |
26 /**/ () { | 26 /**/ () { |
27 // Use nothing. | 27 // Use nothing. |
28 }; | 28 }; |
29 localVar = 43; | 29 localVar = 43; |
30 return localVar; | 30 return localVar; |
31 } | 31 } |
32 | 32 |
33 /*mutateInOtherClosure:box=(box0 which holds [localVar])*/ | 33 /*element: mutateInOtherClosure:box=(box0 which holds [localVar])*/ |
34 mutateInOtherClosure() { | 34 mutateInOtherClosure() { |
35 var /*boxed*/ localVar; | 35 var /*boxed*/ localVar; |
36 /*free=[box0,localVar]*/ () { | 36 /*free=[box0,localVar]*/ () { |
37 print(localVar); | 37 print(localVar); |
38 }; | 38 }; |
39 /*free=[box0,localVar]*/ () { | 39 /*free=[box0,localVar]*/ () { |
40 localVar = 44; | 40 localVar = 44; |
41 }; | 41 }; |
42 /**/ () { | 42 /**/ () { |
43 // Use nothing. | 43 // Use nothing. |
44 }; | 44 }; |
45 return localVar; | 45 return localVar; |
46 } | 46 } |
47 | 47 |
48 /*mutateInNestedClosure:box=(box0 which holds [localVar])*/ | 48 /*element: mutateInNestedClosure:box=(box0 which holds [localVar])*/ |
49 mutateInNestedClosure() { | 49 mutateInNestedClosure() { |
50 var /*boxed*/ localVar; | 50 var /*boxed*/ localVar; |
51 /*free=[box0,localVar]*/ () { | 51 /*free=[box0,localVar]*/ () { |
52 print(localVar); | 52 print(localVar); |
53 /*free=[box0,localVar]*/ () { | 53 /*free=[box0,localVar]*/ () { |
54 localVar = 45; | 54 localVar = 45; |
55 }; | 55 }; |
56 /**/ () { | 56 /**/ () { |
57 // Use nothing. | 57 // Use nothing. |
58 }; | 58 }; |
59 }; | 59 }; |
60 /**/ () { | 60 /**/ () { |
61 // Use nothing. | 61 // Use nothing. |
62 }; | 62 }; |
63 return localVar; | 63 return localVar; |
64 } | 64 } |
65 | 65 |
66 main() { | 66 main() { |
67 mutateInClosure(); | 67 mutateInClosure(); |
68 mutateOutsideClosure(); | 68 mutateOutsideClosure(); |
69 mutateInOtherClosure(); | 69 mutateInOtherClosure(); |
70 mutateInNestedClosure(); | 70 mutateInNestedClosure(); |
71 } | 71 } |
OLD | NEW |