Skip to content

Accept integer-valued floats as slice/string indices#21

Merged
myzie merged 1 commit into
mainfrom
float-index
May 8, 2026
Merged

Accept integer-valued floats as slice/string indices#21
myzie merged 1 commit into
mainfrom
float-index

Conversation

@myzie
Copy link
Copy Markdown
Contributor

@myzie myzie commented May 8, 2026

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.

Test plan

  • go test ./...
  • go test -race ./...
  • go test -run=^$ -fuzz=FuzzCompile -fuzztime=20s .
  • go test -run=^$ -fuzz=FuzzEval -fuzztime=20s .

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.
@myzie myzie merged commit 5640488 into main May 8, 2026
1 check passed
@myzie myzie deleted the float-index branch May 8, 2026 14:55
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant