fix slice low/high index shadowing variables in vm (#394)
This commit is contained in:
parent
dfcfd6661c
commit
a419bfc93a
2 changed files with 19 additions and 10 deletions
20
vm.go
20
vm.go
|
@ -376,8 +376,8 @@ func (v *VM) run() {
|
||||||
|
|
||||||
var lowIdx int64
|
var lowIdx int64
|
||||||
if low != UndefinedValue {
|
if low != UndefinedValue {
|
||||||
if low, ok := low.(*Int); ok {
|
if lowInt, ok := low.(*Int); ok {
|
||||||
lowIdx = low.Value
|
lowIdx = lowInt.Value
|
||||||
} else {
|
} else {
|
||||||
v.err = fmt.Errorf("invalid slice index type: %s",
|
v.err = fmt.Errorf("invalid slice index type: %s",
|
||||||
low.TypeName())
|
low.TypeName())
|
||||||
|
@ -391,8 +391,8 @@ func (v *VM) run() {
|
||||||
var highIdx int64
|
var highIdx int64
|
||||||
if high == UndefinedValue {
|
if high == UndefinedValue {
|
||||||
highIdx = numElements
|
highIdx = numElements
|
||||||
} else if high, ok := high.(*Int); ok {
|
} else if highInt, ok := high.(*Int); ok {
|
||||||
highIdx = high.Value
|
highIdx = highInt.Value
|
||||||
} else {
|
} else {
|
||||||
v.err = fmt.Errorf("invalid slice index type: %s",
|
v.err = fmt.Errorf("invalid slice index type: %s",
|
||||||
high.TypeName())
|
high.TypeName())
|
||||||
|
@ -428,8 +428,8 @@ func (v *VM) run() {
|
||||||
var highIdx int64
|
var highIdx int64
|
||||||
if high == UndefinedValue {
|
if high == UndefinedValue {
|
||||||
highIdx = numElements
|
highIdx = numElements
|
||||||
} else if high, ok := high.(*Int); ok {
|
} else if highInt, ok := high.(*Int); ok {
|
||||||
highIdx = high.Value
|
highIdx = highInt.Value
|
||||||
} else {
|
} else {
|
||||||
v.err = fmt.Errorf("invalid slice index type: %s",
|
v.err = fmt.Errorf("invalid slice index type: %s",
|
||||||
high.TypeName())
|
high.TypeName())
|
||||||
|
@ -465,8 +465,8 @@ func (v *VM) run() {
|
||||||
var highIdx int64
|
var highIdx int64
|
||||||
if high == UndefinedValue {
|
if high == UndefinedValue {
|
||||||
highIdx = numElements
|
highIdx = numElements
|
||||||
} else if high, ok := high.(*Int); ok {
|
} else if highInt, ok := high.(*Int); ok {
|
||||||
highIdx = high.Value
|
highIdx = highInt.Value
|
||||||
} else {
|
} else {
|
||||||
v.err = fmt.Errorf("invalid slice index type: %s",
|
v.err = fmt.Errorf("invalid slice index type: %s",
|
||||||
high.TypeName())
|
high.TypeName())
|
||||||
|
@ -502,8 +502,8 @@ func (v *VM) run() {
|
||||||
var highIdx int64
|
var highIdx int64
|
||||||
if high == UndefinedValue {
|
if high == UndefinedValue {
|
||||||
highIdx = numElements
|
highIdx = numElements
|
||||||
} else if high, ok := high.(*Int); ok {
|
} else if highInt, ok := high.(*Int); ok {
|
||||||
highIdx = high.Value
|
highIdx = highInt.Value
|
||||||
} else {
|
} else {
|
||||||
v.err = fmt.Errorf("invalid slice index type: %s",
|
v.err = fmt.Errorf("invalid slice index type: %s",
|
||||||
high.TypeName())
|
high.TypeName())
|
||||||
|
|
|
@ -1090,6 +1090,15 @@ export func() {
|
||||||
b := 5
|
b := 5
|
||||||
return b + "foo"
|
return b + "foo"
|
||||||
}`), "Runtime Error: invalid operation: int + string\n\tat mod2:4:9")
|
}`), "Runtime Error: invalid operation: int + string\n\tat mod2:4:9")
|
||||||
|
|
||||||
|
expectError(t, `a := [1, 2, 3]; b := a[:"invalid"];`, nil,
|
||||||
|
"Runtime Error: invalid slice index type: string")
|
||||||
|
expectError(t, `a := immutable([4, 5, 6]); b := a[:false];`, nil,
|
||||||
|
"Runtime Error: invalid slice index type: bool")
|
||||||
|
expectError(t, `a := "hello"; b := a[:1.23];`, nil,
|
||||||
|
"Runtime Error: invalid slice index type: float")
|
||||||
|
expectError(t, `a := bytes("world"); b := a[:time(1)];`, nil,
|
||||||
|
"Runtime Error: invalid slice index type: time")
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestVMErrorUnwrap(t *testing.T) {
|
func TestVMErrorUnwrap(t *testing.T) {
|
||||||
|
|
Loading…
Reference in a new issue