Fix: stop execution when trying to slice an unsupported type (#443)

This commit is contained in:
Max Kuznetsov 2024-02-25 07:47:25 +00:00 committed by GitHub
parent 47062da36a
commit c461a7fe60
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
2 changed files with 2 additions and 0 deletions

1
vm.go
View file

@ -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])

View file

@ -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(