Skip to content

Commit

Permalink
fix: add special case error when a parameter/index overflows int (goo…
Browse files Browse the repository at this point in the history
  • Loading branch information
tdakkota authored Sep 29, 2020
1 parent 6e684ef commit 88a1093
Show file tree
Hide file tree
Showing 3 changed files with 4 additions and 4 deletions.
4 changes: 2 additions & 2 deletions starlark/eval.go
Original file line number Diff line number Diff line change
Expand Up @@ -1163,7 +1163,7 @@ func slice(x, lo, hi, step_ Value) (Value, error) {
var err error
step, err = AsInt32(step_)
if err != nil {
return nil, fmt.Errorf("got %s for slice step, want int", step_.Type())
return nil, fmt.Errorf("invalid slice step: %s", err)
}
if step == 0 {
return nil, fmt.Errorf("zero is not a valid slice step")
Expand Down Expand Up @@ -1257,7 +1257,7 @@ func asIndex(v Value, len int, result *int) error {
var err error
*result, err = AsInt32(v)
if err != nil {
return fmt.Errorf("got %s, want int", v.Type())
return err
}
if *result < 0 {
*result += len
Expand Down
2 changes: 1 addition & 1 deletion starlark/library.go
Original file line number Diff line number Diff line change
Expand Up @@ -207,7 +207,7 @@ func chr(thread *Thread, _ *Builtin, args Tuple, kwargs []Tuple) (Value, error)
}
i, err := AsInt32(args[0])
if err != nil {
return nil, fmt.Errorf("chr: got %s, want int", args[0].Type())
return nil, fmt.Errorf("chr: %s", err)
}
if i < 0 {
return nil, fmt.Errorf("chr: Unicode code point %d out of range (<0)", i)
Expand Down
2 changes: 1 addition & 1 deletion starlark/testdata/string.star
Original file line number Diff line number Diff line change
Expand Up @@ -128,7 +128,7 @@ assert.eq("banana"[::-1], "ananab")
assert.eq("banana"[None:None:-2], "aaa")
assert.fails(lambda: "banana"[1.0::], "invalid start index: got float, want int")
assert.fails(lambda: "banana"[:"":], "invalid end index: got string, want int")
assert.fails(lambda: "banana"[:"":True], "got bool for slice step, want int")
assert.fails(lambda: "banana"[:"":True], "invalid slice step: got bool, want int")

# in, not in
assert.true("oo" in "food")
Expand Down

0 comments on commit 88a1093

Please sign in to comment.