ReviewOS

home-lang/home

Regression: `&array[i]` / `&struct.field` returns value type instead of pointer-to-value after #22

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

Context

home #22's deref-then-index sub-item (`(*ptr)[i]` parser fix) introduced a typechecker regression on the related `&expr[i]` / `&expr.field` lvalue-address-taking path.

The 2026-05-04-evening audit shows 38 first-error `Argument type mismatch` failures, mostly where call sites pass `&array[i]` or `&struct.field` and the typechecker reports the value type instead of `*ValueType`. Plus likely ~30 more cascaded.

Reproduction patterns

```home struct Bridge { ports: [16]Port, ip_addr: u32 } fn use_port(p: Port) { / ... */ } fn use_ip(ip: u32) { / ... */ }

fn caller(br: *Bridge) { use_port(&br.ports[0]) // fails: expected *Port, found Port use_ip(&br.ip_addr) // fails: expected *u32, found u32 } ```

The expressions `&br.ports[0]` and `&br.ip_addr` should produce pointer-to-element / pointer-to-field types. Currently producing the underlying value type.

Affected files (from audit)

  • `arch/arm64/gic400.home`, `arch/arm64/gic600.home` ("expected: pointer to InterruptDescriptor, found: InterruptDescriptor")
  • `block/readahead.home`, `block/request_merge.home`
  • Many `drivers/` and `net/` files with similar shapes

Full list: filter `~/Desktop/home-os-kernel-audit-2026-05-04-evening.tsv` for `first_error` = `Argument type mismatch`.

Fix

In `packages/types/src/type_system.zig`, the address-of (`&`) typing path. When applied to:

  • `expr[i]` where `expr` is array/pointer-to-array → result type is `*ElementType` (already pointer if `expr` is pointer)
  • `expr.field` where `expr` is struct/pointer-to-struct → result type is `*FieldType`
  • `(*ptr)[i]` deref-then-index (the #22 case) → already handled, but check that taking `&` of this produces `*ElementType` not `ElementType`

Likely 10-30 lines of adjustment to how the unary-address operator types its operand.

Why this matters

Second-highest leverage regression fix from the evening audit. Pure correctness bug — taking the address of an lvalue should always produce a pointer type. Estimated +25 to +40 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 #22 (deref-then-index part)

Sign in to comment on this issue.