Skip to content

Commit

Permalink
Throw a runtime error when trying to slice an unsupported type (#442)
Browse files Browse the repository at this point in the history
  • Loading branch information
mkuznets committed Feb 24, 2024
1 parent 18b953c commit 9d35005
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 0 deletions.
2 changes: 2 additions & 0 deletions vm.go
Original file line number Diff line number Diff line change
Expand Up @@ -534,6 +534,8 @@ func (v *VM) run() {
}
v.stack[v.sp] = val
v.sp++
default:
v.err = fmt.Errorf("not indexable: %s", left.TypeName())
}
case parser.OpCall:
numArgs := int(v.curInsts[v.ip+1])
Expand Down
6 changes: 6 additions & 0 deletions vm_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -3634,6 +3634,12 @@ func TestSpread(t *testing.T) {
"Runtime Error: wrong number of arguments: want=3, got=2")
}

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")
}

func expectRun(
t *testing.T,
input string,
Expand Down

0 comments on commit 9d35005

Please sign in to comment.