Skip to content

Casting an infinite constant float to an integer type crashes the compiler with OverflowError #229

Description

@zimri-leisher

const_convert_type catches the ValueError that int() raises for NaN but not the OverflowError it raises for infinity, so casting a non-finite constant to any integer type escapes as an uncaught Python exception. An infinite constant is easy to produce today because out-of-range float constants fold to inf (#110), and the crash fires in every position that coerces the cast: assignments, command arguments, array indices, range bounds, exit and assert codes. Both backends crash with a traceback; the NaN variant of the same casts correctly reports For type F64: cannot convert float NaN to integer.

x: I64 = I64(F64(1e999))                                   # OverflowError: cannot convert float infinity to integer
y: U8 = U8(F64(1e999))                                     # same
CdhCore.cmdDisp.CMD_TEST_CMD_1(I32(F64(1e999)), 1.0, 1)   # same
for i in 0..I64(F64(1e999)):                               # same
    pass

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions