Reject out-of-range numeric casts - #804
Merged
Merged
Conversation
Return no value when INT or FLOAT cannot represent their input instead of clamping or panicking. Fixes knowsys#803
mattfaltyn
force-pushed
the
fix-numeric-cast-bounds
branch
from
August 12, 2026 20:14
82e0297 to
d6bd67f
Compare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
INTinstead of saturating themFLOATproduces a non-finite valueWhy
Numeric casts are partial operations: inputs that the target datatype cannot represent should produce no value. Previously, Rust's
as i64conversion silently clamped large floating-point values toi64::MINori64::MAX, while double-to-float overflow reached anexpectand panicked the process.The implementation now uses the existing checked numeric conversion for integer targets and propagates the float constructor's error as
None.Fixes #803.
Testing
cargo test --workspacecargo test --workspace function::evaluation::test::evaluate_casting -- --exactcargo fmt --all -- --checkRUSTFLAGS=-Dwarnings cargo clippy --all-targets --workspace --verboseRUSTFLAGS=-Dwarnings RUSTDOCFLAGS=-Dwarnings cargo doc --workspacepycodestyle nemo-pythonnemo-cliand reran both issue reproductions; invalid casts emit no fact, while a valid control still emits42Local environment limitations
bytecount: Miri does not support the invoked AArch64 NEON intrinsicnemo-physicalMiri run is blocked before this test by an existing#[tokio::test]expansion error on the local Apple/nightly toolchainmaturin, which is not installed locallywasm-packand configured Firefox/Chrome executables, which are not installed locallyThe repository's Linux CI covers these platform-dependent jobs.