diff --git a/runtime/vm.go b/runtime/vm.go index 69e10664..07f6e530 100644 --- a/runtime/vm.go +++ b/runtime/vm.go @@ -859,9 +859,12 @@ func (v *VM) run() { val := v.stack[v.sp-numSelectors-1] v.sp -= numSelectors + 1 - sp := v.curFrame.basePointer + localIndex + dst := v.stack[v.curFrame.basePointer+localIndex] + if obj, ok := dst.(*objects.ObjectPtr); ok { + dst = *obj.Value + } - if e := indexAssign(v.stack[sp], val, selectors); e != nil { + if e := indexAssign(dst, val, selectors); e != nil { v.err = e return } diff --git a/runtime/vm_function_test.go b/runtime/vm_function_test.go index 820f8da9..9a481cd1 100644 --- a/runtime/vm_function_test.go +++ b/runtime/vm_function_test.go @@ -52,6 +52,16 @@ func TestFunction(t *testing.T) { out = f2(10); `, nil, 60) + expect(t, ` + f1 := func(f) { + a := [undefined] + a[0] = func() { return f(a) } + return a[0]() + } + + out = f1(func(a) { return 2 }) + `, nil, 2) + // closures expect(t, ` newAdder := func(x) {