Skip to content

Commit b5e558e

Browse files
Fix GC bug when using morpho_call and a class...
1 parent 5ecf3f6 commit b5e558e

2 files changed

Lines changed: 15 additions & 1 deletion

File tree

src/core/vm.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1886,7 +1886,7 @@ bool morpho_call(vm *v, value f, int nargs, value *args, value *ret) {
18861886
} else morpho_runtimeerror(v, VM_NOINITIALIZER, MORPHO_GETCSTRING(klass->name));
18871887

18881888
if (success) {
1889-
vm_bindobject(v, obj);
1889+
vm_bindobjectwithoutcollect(v, obj); // 4/2/25 Changed to disable collection because we can't guarantee the external context of the caller (e.g. apply)
18901890
*ret = obj;
18911891
} else morpho_freeobject(obj);
18921892
} else morpho_runtimeerror(v, VM_INSTANTIATEFAILED);

test/apply/apply_optionals.morpho

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
// Apply a function with optional arguments
2+
3+
fn f(x,y=0,z=0) {
4+
return x*x+y*y+z*z;
5+
}
6+
7+
print apply(f, 0.5, y=0.2, z=0.1)
8+
// expect: 0.3
9+
10+
print apply(f, 0.5)
11+
// expect: 0.25
12+
13+
print apply(f, 0.5, q=1)
14+
// expect error 'InvldArgs'

0 commit comments

Comments
 (0)