ReviewOS

home-lang/home

Regression: large u64 hex literals rejected after #21 (e.g. `var x: u64 = 0xFFFF000000000000`)

#24
Closed glennmichael123 opened this 24 days ago · 0 comments
24 days ago

Context

home #21 (literal context propagation) introduced a regression: integer literals that fit in the destination unsigned type but exceed `i64.max` are now rejected with `integer literal does not fit in destination type`.

The 2026-05-04-evening audit found this is the dominant new failure pattern, with 17 direct first-error files + ~10 cascades. Affected files include:

  • `arch/arm64/mmu.home`
  • `core/vfs_buffer_cache.home`
  • `fs/ext2.home`
  • `mm/slab.home`
  • `mm/vmalloc.home`
  • `net/wireguard.home`
  • `realtime/rt_scheduler.home`
  • `sched/scheduler.home`
  • `security/kernel_user_split.home`
  • `security/ptr_safety.home`

Plus more — full set in `~/Desktop/home-os-kernel-audit-2026-05-04-evening.tsv` filtering `first_error` = `integer literal does not fit in destination type`.

Reproduction

```home var kernel_start: u64 = 0xFFFF000000000000 // fails: integer literal does not fit ```

The literal `0xFFFF000000000000` fits in u64 (it's a valid u64 value), but doesn't fit in i64 (overflows since high bit set). The current `integerLiteralFits` check stores the value as i64 internally, so any positive integer > i64.max is rejected even if the destination is u64.

Fix

In `packages/types/src/type_system.zig`, the `integerLiteralFits(value: i64, dest: Type)` function. The fix is to widen the value-storage type or special-case unsigned destinations:

  • Option A: change the value parameter from `i64` to `u64` for unsigned destination types and check accordingly
  • Option B: change the storage to `i128` so all i64+u64 values fit, then range-check by destination
  • Option C: when parsing the literal, detect "positive literal that overflows i64 but fits u64" and store as a separate "u64 literal" token type

Option B is cleanest. Probably ~10-20 lines.

Test cases

  • `var a: u64 = 0xFFFF000000000000` → accept (value < u64.max)
  • `var b: u64 = 0xFFFFFFFFFFFFFFFF` → accept (= u64.max)
  • `var c: u64 = -1` → reject (negative for unsigned)
  • `var d: i64 = 0xFFFF000000000000` → reject (overflow signed)
  • `var e: u32 = 0xFFFFFFFFFF` → reject (overflow u32)

Why this matters

Highest-leverage regression fix from the evening audit. Pure correctness bug — the literal IS valid, the typechecker was wrong to reject it. Estimated +22 to +27 OK modules in home-os.

Reference

  • 2026-05-04-evening audit: `~/Desktop/home-os-kernel-audit-2026-05-04-evening.tsv`
  • Original feature: home-lang/home #21

Sign in to comment on this issue.