Throw a runtime error when trying to slice an unsupported type (#442)
This commit is contained in:
parent
18b953c7be
commit
9d35005ffe
2 changed files with 8 additions and 0 deletions
2
vm.go
2
vm.go
|
@ -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])
|
||||
|
|
|
@ -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,
|
||||
|
|
Loading…
Reference in a new issue