Skip to content

Conversation

@rtfeldman
Copy link
Contributor

Summary

When code like 1E10.e is type-checked, the type system infers that the number literal must have type { e: _ } (a record with field e). At runtime, the numeric literal evaluation functions would use this inferred record layout, but the record has size 0 (since the field is an unresolved flex var), resulting in a null pointer. When field access was then attempted on this "record", the code crashed with an assertion failure.

  • Added layout compatibility checks to evalDec, evalFracF64, and evalFracF32 similar to what evalNum and evalDecSmall already have
  • When the inferred layout is not compatible with the literal type, we fall back to the appropriate numeric layout (Dec, F64, or F32)
  • This allows the type checker to report a proper error message instead of the interpreter crashing
  • Added a snapshot test to verify the fix

Fixes #9000

Co-authored by Claude Opus 4.5

When code like `1E10.e` is type-checked, the type system infers that
the number literal must have type `{ e: _ }` (a record with field `e`).
At runtime, the numeric literal evaluation functions (evalDec,
evalFracF64, evalFracF32) would use this inferred record layout, but
the record has size 0 (since the field is an unresolved flex var),
resulting in a null pointer. When field access was then attempted on
this "record", the code crashed with an assertion failure.

The fix adds layout compatibility checks to evalDec, evalFracF64, and
evalFracF32 similar to what evalNum and evalDecSmall already have.
When the inferred layout is not compatible with the literal type, we
fall back to the appropriate numeric layout (Dec, F64, or F32). This
allows the type checker to report a proper error message instead of
the interpreter crashing.

Fixes #9000

Co-Authored-By: Claude Opus 4.5 <[email protected]>
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.

panic: reached unreachable code

2 participants