ReviewOS

home-lang/home

Parser rejects `fn name(args)` forward declarations (no body)

#17
Closed glennmichael123 opened this 24 days ago · 1 comment
24 days ago

Context

Surfaced while migrating home-os kernel module-scope vars to explicit init (home-lang/home-os #13). `drivers/pci.home` line 88 has a `fn` forward declaration with no body:

```home fn pci_scan_bus(bus: u8) ```

The parser doesn't accept this form. It emits errors that hide downstream scope — even after the var-init fixes, line 93's `pci_bus_visited` shows up as an "Undefined variable" rather than parsing cleanly.

Why this matters

Forward declarations are a useful kernel pattern for breaking circular references between functions defined later in the file (or for declaring functions defined in assembly / linked-in code). The home-os kernel uses them in at least `drivers/pci.home`; likely more spots once a clean parser pass is possible.

Proposal

Either:

  1. Accept `fn name(args)` (no body) as a forward declaration — parses to a function signature with no body, type-checks against any later definition or external symbol
  2. Require an explicit `extern`-like marker — e.g. `extern fn pci_scan_bus(bus: u8);` — so the intent is unambiguous

(1) is more concise; (2) is more explicit. Either is a clear language-design call.

Reproduction

```bash echo 'fn forward_decl(x: u8) fn forward_decl(x: u8) { let y = x }' > /tmp/fwd.home ./zig-out/bin/home-debug ast /tmp/fwd.home ```

  • home-lang/home-os #13 close comment cites this as out-of-scope discovery
  • home-lang/home-os audit (2026-05-01) likely had this contribute to the parse-failure bucket — ready to be re-evaluated now that the parser-hang (home-lang/home #16) is fixed
24 days ago

Fix landed in c73c0bf: same-line return-type adjacency + body-less signatures parse as forward declarations (is_forward_decl), name-binding-only semantics across all 4 codegen backends + interpreter. Repro parses clean (2 statements).

Sign in to comment on this issue.