Skip to content

Report a diagnostic when a non-finite float constant is cast to an integer (#229) - #237

Open
zimri-leisher wants to merge 1 commit into
develfrom
229-nonfinite-float-to-int
Open

Report a diagnostic when a non-finite float constant is cast to an integer (#229)#237
zimri-leisher wants to merge 1 commit into
develfrom
229-nonfinite-float-to-int

Conversation

@zimri-leisher

Copy link
Copy Markdown
Collaborator

Fixes #229.

const_convert_type caught the ValueError that int() raises for NaN but
not the OverflowError it raises for infinity, so casting an infinite constant
to any integer type escaped as an uncaught Python exception in every position
that coerces the cast (assignments, command arguments, array indices, range
bounds, exit and assert codes). Listing OverflowError alongside
ValueError gives it the same diagnostic the NaN case already gets:
For type F64: cannot convert float infinity to integer.

Red/green: the two infinity sequences crash with OverflowError: cannot convert float infinity to integer before the change and report a compile error after;
the NaN sequence guards the branch that already worked. They reach infinity by
overflowing a float multiply/add rather than through an out-of-range literal, so
they stay valid independently of #110.

🤖 Generated with Claude Code

…ant is cast to an integer (#229)

Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
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