You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Return-type inference only covers single-expression bodies; 'return <value>' inside an inferred-Unit fn is silently accepted #659
§29.13 function forms (docs/with-specification.md:3251): "The return type -> TYPE is omitted when the function returns Unit (void)."
§4.6 inference (docs/with-specification.md:2127): "Inside function bodies, types are inferred. At module boundaries, types must be explicit."
Mission / AGENTS.md style: "Don't spell types the compiler can infer — omit a return type when the body makes it obvious (fn shout(s: str): s ++ \"!\")."
Facts (verified by running)
The implementation infers the return type for single-expression bodies only, including across module boundaries and for pub methods:
Any block body with an early return false and a bool tail expression infers Unit — free functions and methods alike. Callers then see Unit ("argument expression 'a.contains(id0)' has type Unit").
The return false inside the inferred-Unit function is silently accepted — no diagnostic — so the error surfaces only at call sites (or as the misleading "return type does not implement Default").
Reduced matrix: scratchpad v_a.w (works) / v_b.w / v_c.w (fail). Real-world instance: src/compiler/foundation/{Arena,SourceMap,Diagnostic}.w were written expecting block-body inference; 6 of 12 test/internals files failed at the baseline (10f7771e) — masked until the spec suite went green because :test stopped at the earlier failure. Fixed for now by annotating the return types.
The fork to settle
Extend inference to block bodies (early returns + tail expression must agree), which the mission text favors — but §4.6's "at module boundaries, types must be explicit" argues the opposite for pub surfaces, and single-expression inference already crosses module boundaries today.
Keep omitted = Unit for block bodies (spec as written) — then the missing diagnostic is the bug: return <value> in a Unit-typed function must be rejected loudly, which would have caught the foundation modules at compile time.
Either ruling needs the diagnostic; the choice between them is a design call (decisions.md material).
Workaround in tree
Explicit -> TYPE annotations added to the affected foundation functions.
Fixed in e7ffc47 — same root cause as #653 (return value type not recorded for bool/binary kinds → inference misreads value-return as bare → Unit → undef branch trap). is_small(3) now prints 'small'. See #653 for the full analysis; fixtures behav_infer_return_early_comparison + behav_infer_return_early_logical cover this shape.
Activity
Foundation: annotate block-body return types (fixes internals-tests)
Sema: fix return-type inference for early value returns (#653, #659, #…
ehartford commentedon Jul 14, 2026
Fixed in e7ffc47 — same root cause as #653 (return value type not recorded for bool/binary kinds → inference misreads value-return as bare → Unit → undef branch trap). is_small(3) now prints 'small'. See #653 for the full analysis; fixtures behav_infer_return_early_comparison + behav_infer_return_early_logical cover this shape.