summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--pez.c3
-rw-r--r--test.pez16
2 files changed, 14 insertions, 5 deletions
diff --git a/pez.c b/pez.c
index 16f7f2a..b2e590c 100644
--- a/pez.c
+++ b/pez.c
@@ -2170,6 +2170,7 @@ findupval(Comp *cm, Local **pl, struct fenv *fenv, const char *name)
Local *l = &fenv->prev->locals.at[i];
if (!strcmp(&cm->spool.at[l->sref], name)) {
assert(!l->has_k); // would've been found by findlocal earlier
+ l->captured = 1;
*pl = l;
return addupval(cm, fenv, l->index, l->isparam, !l->isparam);
}
@@ -2192,7 +2193,7 @@ endscope(Comp *cm)
} else {
if (!l->has_k) {
--cm->fenv.nvars;
- if (l->mutable && l->scope > 0) {
+ if (l->mutable && l->scope > 0 && l->captured) {
TRY(compop(cm, Oclose) && compbyte(cm, l->index));
}
}
diff --git a/test.pez b/test.pez
index 1dbdfc6..118be00 100644
--- a/test.pez
+++ b/test.pez
@@ -1,10 +1,18 @@
@print: {[x] printf["%a\n", x]}
@Box: {[value]
- @test = 7
- #[{value},
- {[new] printf["test: %a\n", test] value = new}]
- }
+ @it = 0
+ (
+ @test = 7
+ @h2 = 100
+ it = #[{value},
+ {[new] printf["test: %a\n", test] value = new}]
+ )
+ (
+ @hmm = 999
+ )
+ it
+}
@x = Box[-7]