File tree Expand file tree Collapse file tree 3 files changed +18
-11
lines changed
Expand file tree Collapse file tree 3 files changed +18
-11
lines changed Original file line number Diff line number Diff line change 11---
22expected_error_type: none
33---
4- // The closure should capture the globally defined function and redeclaring
5- // a function with the same name should not affect the closure's capture.
4+ // This function is used in the function `f` below.
65fun global() {
76 print "global";
87}
@@ -12,9 +11,12 @@ fun global() {
1211 global();
1312 }
1413
15- f();
14+ f(); // this should print "global"
15+
16+ // This function declaration shouldn't affect the usage in `f` above.
1617 fun global() {
1718 print "local";
1819 }
19- f();
20+
21+ f(); // this should also print "global"
2022}
Original file line number Diff line number Diff line change 11---
22expected_error_type: none
33---
4- // The `inner` function should capture the variable from the closest outer
5- // scope, which is the `outer` function's scope.
64var x = "global";
75
86fun outer() {
97 var x = "outer";
108
119 fun middle() {
10+ // The `inner` function should capture the variable from the closest outer
11+ // scope, which is the `outer` function's scope.
1212 fun inner() {
1313 print x; // Should capture "outer", not "global"
1414 }
1515
16- inner();
16+ inner(); // Should print "outer"
17+
18+ // This variable declaration shouldn't affect the usage in `inner` above.
1719 var x = "middle";
20+
1821 inner(); // Should still print "outer"
1922 }
2023
Original file line number Diff line number Diff line change 11---
22expected_error_type: none
33---
4- // The closure should capture the `count` variable from the global scope
5- // and increment it. Reassigning the `count` variable in the local scope
6- // should not affect the closure's capture.
74var count = 0;
85
96{
7+ // The `counter` function should use the `count` variable from the
8+ // global scope.
109 fun makeCounter() {
1110 fun counter() {
11+ // This should increment the `count` variable from the global scope.
1212 count = count + 1;
1313 print count;
1414 }
@@ -19,6 +19,8 @@ var count = 0;
1919 counter1(); // Should print 1
2020 counter1(); // Should print 2
2121
22- var count = 0; // This local variable shouldn't affect our counter
22+ // This variable declaration shouldn't affect our counter.
23+ var count = 0;
24+
2325 counter1(); // Should print 3
2426}
You can’t perform that action at this time.
0 commit comments