Skip to content

Commit

Permalink
Fix type casting with mixed arguments in randint
Browse files Browse the repository at this point in the history
  • Loading branch information
MrOverlord authored and xiaq committed Jan 5, 2025
1 parent 8737735 commit d078bc1
Showing 1 changed file with 9 additions and 1 deletion.
10 changes: 9 additions & 1 deletion pkg/eval/builtin_fn_num.go
Original file line number Diff line number Diff line change
Expand Up @@ -375,7 +375,15 @@ func randint(args ...vals.Num) (vals.Num, error) {
if len(args) == 1 {
low, high = big.NewInt(0), args[0].(*big.Int)
} else {
low, high = args[0].(*big.Int), args[1].(*big.Int)
var casted_args [2]*big.Int
for i, arg := range args {
if casted_arg, ok := arg.(*big.Int); ok {
casted_args[i] = casted_arg
} else {
casted_args[i] = big.NewInt(int64(arg.(int)))
}
}
low, high = casted_args[0], casted_args[1]
}
if high.Cmp(low) <= 0 {
return 0, errs.BadValue{What: "high value",
Expand Down

0 comments on commit d078bc1

Please sign in to comment.