Problem
The parser does not accept ErrorSet!T error-union types as function return types. Today this fails with error[EP0001]: Expected '{':
pub fn check_kernel_buffer(ptr: usize, size: usize, write: bool) UsercopyError!void {
...
}Column points at !. The parser stops at UsercopyError, treats it as a complete type, then sees !void { and demands { (the function body) — the ! is mis-parsed.
Background
In Zig, ErrorSet!T denotes a type that is either an error from the set or a value of type T. The default error set form !T (no explicit error set) is also valid.
Affected kernel files (sample)
- kernel/src/security/hardened_usercopy.home:159 (
UsercopyError!void) - many others using
Error!Tpatterns — full count requires another grep but easily 30+ sites kernel-wide
Expected behavior
In type position (function return, struct field, variable annotation, type alias), accept:
ErrorSet!T // explicit error set
!T // anonymous error set
*ErrorSet!T // optionally combined with prefix-position type formsLowering: typecheck-time, parser produces an ErrorUnionType AST node with error_set and payload slots.
Implementation hint
In parseTypeAnnotation (or wherever return types are parsed), after consuming an identifier that looks like a type name, peek for !:
- If next is
!, consume it, parse another type expression as the payload, returnType.ErrorUnion{ .error_set = first, .payload = second }. - Same for the anonymous form: if the type position starts with
!, parse!Tdirectly.
Tests
Positive:
fn foo(): MyError!void { ... }fn foo(): MyError!u32 { ... }fn foo(): !u32 { ... }(anonymous error set)let x: MyError!u32 = bar();
Regression:
- Existing types keep working
!as boolean-not operator continues to work
Acceptance
- hardened_usercopy.home and other affected files clear
home-debug astpast the!Treturn-type point. - Existing test suite green.