From c461a7fe6043d451d222406fdda3d39438653fea Mon Sep 17 00:00:00 2001 From: Max Kuznetsov Date: Sun, 25 Feb 2024 07:47:25 +0000 Subject: [PATCH] Fix: stop execution when trying to slice an unsupported type (#443) --- vm.go | 1 + vm_test.go | 1 + 2 files changed, 2 insertions(+) diff --git a/vm.go b/vm.go index 2e0240b..74b7742 100644 --- a/vm.go +++ b/vm.go @@ -536,6 +536,7 @@ func (v *VM) run() { v.sp++ default: v.err = fmt.Errorf("not indexable: %s", left.TypeName()) + return } case parser.OpCall: numArgs := int(v.curInsts[v.ip+1]) diff --git a/vm_test.go b/vm_test.go index 49c93de..55a9289 100644 --- a/vm_test.go +++ b/vm_test.go @@ -3638,6 +3638,7 @@ func TestSliceIndex(t *testing.T) { expectError(t, `undefined[:1]`, nil, "Runtime Error: not indexable") expectError(t, `123[-1:2]`, nil, "Runtime Error: not indexable") expectError(t, `{}[:]`, nil, "Runtime Error: not indexable") + expectError(t, `a := 123[-1:2] ; a += 1`, nil, "Runtime Error: not indexable") } func expectRun(