Problem
The parser accepts the Zig-style fn name() Ret { ... } return-type form when there are NO parameters, but fails with error[EP0001]: Expected '{' when parameters are present:
fn foo() ?u32 { return null } // OK — no params
fn foo(name: []const u8) ?[]const u8 { return null } // FAIL — same shape, with param
fn foo(name: []const u8): ?[]const u8 { return null } // OK — adding `:` worksThe parser treats the ?[]const u8 as a continuation of the parameter list rather than as a return type.
Background
Home accepts both:
- TS/Rust-style:
fn foo(): Ret { ... }(:separator) - Zig-style:
fn foo() Ret { ... }(space separator)
The Zig-style works for empty parameter lists but breaks for non-empty ones — clearly a parser inconsistency.
Affected kernel files (10+)
Many files in kernel/src/iot/, kernel/src/security/, kernel/src/drivers/ use the Zig-style with params and currently fail. Examples:
- kernel/src/iot/voice_routines.home:337 (
pub fn get_param(self: *const Action, name: []const u8) ?[]const u8 {) - kernel/src/iot/voice_languages.home:436 (similar)
- kernel/src/iot/audio_processing.home (similar)
- kernel/src/security/dm_verity.home, secure_boot.home, fscrypt.home, etc.
Expected behavior
The parser should accept the Zig-style space-separated return type irrespective of parameter presence. After the closing ) of the parameter list:
- If next token is
:, consume:and parse the return type (existing TS/Rust path). - If next token starts a type expression (
?,*,&,[,Identifier, etc.) AND parameters were non-empty, parse it as a return type (new — fix the gap). - If next token is
{, the function returns void (existing).
Implementation hint
Find the function-decl parameter-list closing parser. After ) is consumed, the return-type detection probably has two paths:
:→ parse return type- else → assume void
The fix: extend path 2 to peek for a type-starter and dispatch into the return-type parser when present. The same logic already works for empty parameter lists; just remove or fix the gating that excludes non-empty param lists.
Tests
Positive (must parse):
fn foo(x: u32) ?u32 { return null }fn foo(x: u32, y: u32) []const u8 { ... }fn foo(x: *const T) Result { ... }- All
fn(args) RetType {}forms with arbitrary RetType
Regression:
fn foo() Ret { ... }(empty params) keeps workingfn foo(): Ret { ... }(TS/Rust-style with colon) keeps workingfn foo() { ... }(no return type) keeps working
Acceptance
- Many kernel files clear
home-debug astpast their fn-signature line. - Existing test suite green.