0030. Diagnose union qualifiers and nullary parentheses precisely
- Status: Accepted
- Date: 2026-10-30
- Plan: M4.3 (review corrections)
- Review: Language semantics
Context
Review found that the M4 diagnostic table has no precise error
for a wrong pattern qualifier or parentheses on a nullary variant.
Reusing E0501 invented a missing variant; accepting
E.C() contradicted ADR-0022's nullary syntax.
Decision
Refine ADR-0022 and the agreed M4 diagnostic table with two
additive codes: E0515 reports that a pattern qualifier is not the
scrutinee's union, with a replacement qualifier. Resolve coverage
and payload binders using the actual union, counting a recognized
variant as seen despite a bad qualifier. E0516 rejects parentheses
on nullary constructors and patterns; help and a replacement show
E.C or C (retaining optional pattern
qualification). These review-required refinements occupy the next
free codes before the reserved E0520–E0529 result/option range;
existing codes keep their meanings.
For nesting, an unbraced arm's synthetic AST block consumes no source depth. Count the active match itself once, matching call accounting; explicit arm braces still count as blocks. The limit remains 256.
Alternatives considered
- Reuse E0501/E0502 — a recognized variant is neither unknown nor missing; this obscures the single qualifier mistake.
- Reuse arity diagnostics — zero arguments and zero binders have matching arity, so E0302/E0505 cannot explain why empty parentheses are rejected.
- Accept both nullary spellings — contradicts the agreed syntax and keeps unnecessary forms that the canonical formatter already removes.
Consequences
JSON goldens register both codes and unit tests recheck their mechanical fixes. Existing valid programs, runtime semantics and emitted C are unchanged. Nesting-limit tests exercise parsing, formatting and both execution backends.