diff --git a/vm.go b/vm.go index 2f8f6fc..2e0240b 100644 --- a/vm.go +++ b/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]) diff --git a/vm_test.go b/vm_test.go index 8c98b5a..49c93de 100644 --- a/vm_test.go +++ b/vm_test.go @@ -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,