Skip to content

Commit

Permalink
Fix: stop execution when trying to slice an unsupported type (#443)
Browse files Browse the repository at this point in the history
  • Loading branch information
mkuznets committed Feb 25, 2024
1 parent 47062da commit c461a7f
Show file tree
Hide file tree
Showing 2 changed files with 2 additions and 0 deletions.
1 change: 1 addition & 0 deletions vm.go
Original file line number Diff line number Diff line change
Expand Up @@ -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])
Expand Down
1 change: 1 addition & 0 deletions vm_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down

0 comments on commit c461a7f

Please sign in to comment.