ReviewOS

home-lang/home

Parser: function type aliases (pub const F = fn(...) Ret)

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

Problem

The parser does not accept fn(...) Ret in type-alias position, even though it likely accepts it elsewhere (e.g. function-pointer fields):

pub const BlockReadFn = fn(lba: u64, count: u32, buffer: [*]u8) bool
pub const SyscallHandler = fn(u64, u64, u64, u64, u64, u64) u64

var block_read_fn: ?BlockReadFn = null
var syscall_table: [MAX_SYSCALLS]?SyscallHandler = undefined

Diagnostic: error[EP0001]: Expected ')' in function type at the ( after fn.

Affected kernel files

  • kernel/src/fs/partition.home:135 (pub const BlockReadFn = fn(...) bool)
  • kernel/src/arch/x86_64/syscall_fast.home:91 (pub const SyscallHandler = fn(...) u64)

Expected behavior

Accept the same fn(...) Ret type grammar in pub const Foo = ... as in struct-field / variable type annotation. Both named and unnamed parameter forms should work:

pub const Named = fn(lba: u64, count: u32) bool;
pub const Unnamed = fn(u64, u32) bool;
pub const NoReturn = fn(u64);            // void
pub const PtrParam = fn(buf: [*]u8) void;
pub const OptArg = ?fn() void;           // nullable

Implementation hint

Where pub const X = ... parses the right-hand side, route through the same type-expression entry point used by struct fields. The fn keyword in type position should produce a Type.Function node whether it's parsed in a struct field, a variable annotation, or a type alias.

Tests

  • Positive: each of the 4 forms above
  • Regression: existing pub const Foo = u32; (primitive alias) keeps working
  • Regression: existing function-pointer field types keep working

Acceptance

  1. The 2 listed kernel files clear home-debug ast past the function-type-alias point.
  2. Existing test suite green.

Sign in to comment on this issue.