fix(compiler): preserve declared type of const references
A const reference lowered to `val(itoa(g.a.ival), "int")` in emit_call.ludic — the initializer's raw integer bits, hardcoded as `int`. For a fixed const like `const X: fixed = 10.0` that yielded the Q16.16 bits (655360) typed as int, so every fixed comparison/arithmetic against it silently broke (it caused an infinite loop in runtime/native/numeric.ludic, previously worked around with inline literals). Fix: a const reference now emits its initializer expression via emit_expr(g.a), which carries the initializer's real type (E_FLOAT->fixed, E_BOOL->bool, E_STR->string) and even handles computed initializers. Every existing const is an int literal, for which this is byte-identical to the old immediate — the C-free bootstrap fixpoint and all golden renders are unchanged. - selfhost/tests/const.ludic + sh_case pin fixed/int/bool const behaviour. - runtime/native/numeric.ludic restored to named fixed consts (HUGE_TEN etc.), which the workaround had inlined; the numeric example (20 assertions) still passes, validating the fix under runtime splice. All suites green: x selfhost-test 31/31 (fixpoint holds, goldens byte-identical), x test 85/85, x test-tools 30/30. Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
This commit is contained in:
parent
790eda6f73
commit
7c91d24595
6 changed files with 3680 additions and 3641 deletions
11
changes/fix-fixed-const-type.md
Normal file
11
changes/fix-fixed-const-type.md
Normal file
|
|
@ -0,0 +1,11 @@
|
|||
bump: patch
|
||||
type: fix
|
||||
**`const` of a non-int type is no longer miscompiled.** A `const` reference used
|
||||
to lower to its initializer's raw integer bits hardcoded as type `int`, so a
|
||||
`const X: fixed = 10.0` compared and computed as the raw Q16.16 value `655360`
|
||||
instead of `10.0` — silently corrupting fixed-point math (and, in one case, spinning
|
||||
an infinite loop). A const reference now emits its initializer expression with that
|
||||
expression's real type, so `fixed` / `bool` / `string` consts behave correctly (and
|
||||
computed const initializers work too). Every existing const is an `int` literal, for
|
||||
which the lowering is byte-identical, so the bootstrap fixpoint and all golden
|
||||
renders are unchanged. Covered by selfhost/tests/const.ludic.
|
||||
Loading…
Add table
Add a link
Reference in a new issue