ReviewOS

home-lang/home

Parser: optional applied to slice/array/pointer types — '?[]T' / '?*T' / '?*?*T'

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

Problem

The parser only handles ?T when T is a single-token type (identifier or primitive). It rejects:

device: ?[]const u8                    // optional slice (struct field)
fn get(): ?[]const u8 { ... }          // optional slice return
tail: ?*?*RcuCallback                  // chained optional/pointer
runtime_suspend: ?fn(d: *D) -> i32     // optional fn-pointer (likely fails too)

Today: error[EP0001]: Expected type name at the type position after ?.

?u32, ?Foo, ?*T (single pointer) all work; the failure is when ? precedes a complex type form.

Affected kernel files (sample)

  • kernel/src/perf/rcu_tree.home:88 (tail: ?*?*RcuCallback)
  • kernel/src/iot/voice_languages.home:387 (device: ?[]const u8 and similar fields)
  • kernel/src/iot/voice_routines.home:337 (?[]const u8 return type)
  • kernel/src/power/device_pm.home (multiple Option<fn(...) -> i32> — distinct issue but related)

Expected behavior

?T should accept any type expression for T, identical to what struct-field type or variable-annotation accepts:

  • ?T (named type)
  • ?u32 (primitive)
  • ?*T (pointer)
  • ?*const T (const pointer)
  • ?*?*T (chained — optional pointer to optional pointer)
  • ?[]T / ?[]const T (slice / const slice)
  • ?[N]T (fixed array)
  • ?fn(...) Ret (optional function pointer)
  • ??T (double optional, not unusual in some contexts)

Implementation hint

Where ? is consumed as an optional-type prefix, recursively call the full parseTypeAnnotation (or whatever entry point handles compound types) instead of the narrow type-name reader. The recursion handles all the nested forms naturally.

Tests

  • Positive: each of the 7 forms above
  • Regression: ?u32, ?Foo, ?*T keep working

Acceptance

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

Sign in to comment on this issue.