The root cause is that math.MaxInt64 0x7fffffffffffffff cannot be exactly represented as a float64 because it has more than 53 bits of precision, so the comparison f <= MaxInt64 actually compares f to the value float64(MaxInt64), which is numerically equal to MaxInt64+1, which of course cannot be exactly represented as an int64. So if f == MaxInt64 the condition is spuriously true. The fix is to add an extra check for this particular value.
Due to inexact int/float comparison at https://github.com/google/starlark-go/blob/master/starlark/int.go#L427.
The root cause is that math.MaxInt64 0x7fffffffffffffff cannot be exactly represented as a float64 because it has more than 53 bits of precision, so the comparison
f <= MaxInt64
actually compares f to the value float64(MaxInt64), which is numerically equal to MaxInt64+1, which of course cannot be exactly represented as an int64. So if f == MaxInt64 the condition is spuriously true. The fix is to add an extra check for this particular value.Pointed out by @algebra8 in https://github.com/google/starlark-go/pull/373/files/3aea0fb3460e9c3764a2d287b573fa1a0465a90d..a73eaa2e67bd3236c52f8ed9c0e22d36b7e8d510