Skip to content

Commit 1c1c982

Browse files
committed
upd
1 parent c908387 commit 1c1c982

File tree

2 files changed

+26
-0
lines changed

2 files changed

+26
-0
lines changed

zenlang/src/vm/vm.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -196,6 +196,8 @@ impl VM {
196196
}
197197

198198
// If refs != 1, the vars are prolly used somewhere else so don't clear them
199+
// TODO: This doesn't work and doesn't pass the fourth test in vm_closure.rs, instead we
200+
// should try using weak ptr's
199201
if refs == 1 {
200202
(&mut *environ.borrow_mut()).vars.clear();
201203
}

zenlang/tests/vm_closure.rs

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -111,3 +111,27 @@ fn main {
111111
Value::Number(3.0),
112112
);
113113
}
114+
115+
#[test]
116+
fn vm_test_closure_4() {
117+
expect_to_return(
118+
r#"
119+
fn closure array {
120+
let x = 5;
121+
let closure = fn {
122+
return x;
123+
};
124+
return closure;
125+
}
126+
127+
fn main {
128+
let arr = [];
129+
let f =closure(arr);
130+
131+
return f();
132+
}
133+
"#
134+
.into(),
135+
Value::Number(5.0),
136+
);
137+
}

0 commit comments

Comments
 (0)