Files
regorus/tests/interpreter/cases/builtins/numbers/mod.yaml
Jay Lorch 839510df56 fix: Prevent panic by Number::modulo (#773)
In Number::modulo, it calls Number::ints_to_bigint, which could panic. The reason is that calling .to_integer() isn't enough to guarantee that .to_bigint_owned() will return Some, but Number::ints_to_bigint assumes it will and calls unwrap(). In particular, it might be that it's a float corresponding to an integer that's larger than F64_SAFE_INTEGER. The fix is to not call Number::ints_to_bigint (and indeed to delete that entire function, which is only used in this one place), and instead only call unwrap when Some is returned.
2026-07-27 14:06:42 -05:00

74 lines
1.3 KiB
YAML

# Copyright (c) Microsoft Corporation.
# Licensed under the MIT License.
cases:
- note: mod
data: {}
modules:
- |
package test
x = 10%3
# Undefined
y { false }
b = y % 1
c = 1 % y
query: data.test
want_result:
x : 1
- note: non-numeric
data: {}
modules:
- |
package test
x = "1" % 9
query: data.test.x
error: "`mod` expects numeric argument."
- note: undefined
data: {}
modules:
- |
package test
a { false }
x = a % 10
query: data.test
want_result: {}
- note: by-zero
data: {}
modules:
- |
package test
x = 1%0
query: data.test
error: modulo by zero
- note: float numerator
data: {}
modules:
- |
package test
x = 1.1 % 1
query: data.test
error: modulo on floating-point number
- note: float denom
data: {}
modules:
- |
package test
x = 1 % 1.1
query: data.test
error: modulo on floating-point number
- note: integral float too large to convert
data: {}
modules:
- |
package test
x = 100000000000000000e-1 % 2
query: data.test
error: modulo on floating-point number