On this page

0030. Diagnose union qualifiers and nullary parentheses precisely

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

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.