Accept integer-valued floats as slice/string indices#21
Merged
Conversation
What: - Add toIndexInt helper that accepts any integer kind plus finite, exactly-integral floats. Non-integer floats, NaN, Inf, out-of-range values, and other non-numeric types report a clean ErrEvaluate "index must be integer". - Use the helper in indexValue's slice/array and string branches in place of the bare toInt64 check. - Pin the new behavior in TestAdversarial_FloatIndexOnSlice (1.0 succeeds, 1.5 errors, both for slices and strings) and document the rule in spec.md and llms.txt. Why: - Mirrors expr's existing "ints and floats are fungible when integral" arithmetic rule. - JSON-derived indices arrive as float64; previously every CLI user had to int(x) the index by hand to avoid a confusing type error.
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.
What
toIndexInthelper that accepts any integer kind plus finite, exactly-integral floats. Non-integer floats, NaN, Inf, out-of-range values, and other non-numeric types report a cleanErrEvaluate"index must be integer".indexValue's slice/array and string branches in place of the baretoInt64check.TestAdversarial_FloatIndexOnSlice(1.0 succeeds, 1.5 errors, both for slices and strings) and document the rule inspec.mdandllms.txt.Why
Mirrors expr's existing "ints and floats are fungible when integral" arithmetic rule. JSON-derived indices arrive as
float64; previously every CLI user had toint(x)the index by hand to avoid a confusing type error.Test plan
go test ./...go test -race ./...go test -run=^$ -fuzz=FuzzCompile -fuzztime=20s .go test -run=^$ -fuzz=FuzzEval -fuzztime=20s .