Repository navigation
Closed
Labels
Description
The rule
In a match arm, => takes the role : plays for every other construct: it introduces the arm's body. The body takes the same three forms as any other body:
match source.next():
Some(task) => thing // inline
Some(task) => // newline, indented block
thing
Some(task) => { // curly braces
thing
}
Some(task): is an error, and the compiler is right to refuse it ("expected '=>'").
What the spec says today
The rule is shown only by example, and two sentences, read literally, say the opposite:
- §9.7 Pattern Matching defines match's two outer forms in prose (block match uses
:after the subject; inline match uses{}around the arms) but never says an arm ispattern [if guard] => body. Arms appear only in examples. The multi-line arm body appears once, in theclick @ MouseClick { … } =>example, and the braced arm body never appears. - §29.13 Block Body Syntax: "After a construct's header, a body introducer is required. For all constructs, including
if,else if, andelse, the introducer must be:or{". With an arm's pattern as its header, this makesSome(x):required and=>illegal. Its "Applies uniformly to all block-introducers" example shows match only in its outer forms, with single-expression arms. - §30.8 Block Syntax lists the three body forms (
COLON_INLINE,COLON_INDENTED,BRACE_BODY, each opening with:or{) as "interchangeable for every block-introducing construct: … labeled blocks, and match arms." - §30.4 Statements (informative grammar) has
MATCH_ARM := PATTERN [ 'if' EXPR ] '=>' EXPR. This is the only place=>is defined, and it allows only an expression, not an indented or braced body. - §29.2 mentions in passing that "Newlines that start a block after
:or=>retain their normal significance", the one hint that=>opens a block.
A reader who follows §29.13 or §30.8 literally writes Some(x): and gets "expected '=>'". This happened while writing std.task.with_concurrency (#981).
What to change
The wording is Eric's; these are the places that need it:
- §9.7: state the arm rule. An arm is a pattern, an optional
ifguard,=>, and a body. The body is inline on the same line, an indented block on the lines below, or a braced block. - §29.13: the "
:or{" introducer rule excepts match arms, whose introducer is=>(§9.7); the uniform example shows the three arm bodies. - §30.8: match arms take the three body forms after
=>, not after:. - §30.4:
MATCH_ARM := PATTERN [ 'if' EXPR ] '=>' ARM_BODY, withARM_BODYcovering the inline expression, the indented block andBRACE_BODY.
The compiler already implements this rule (Parser.parse_match_arms and parse_inline_match_arms in src/Parser.w), so this is a spec-only change. A test of all three arm-body forms would pin it (Law 10).
Activity
Spec: a match arm is `pattern [if guard] => body`, in the three body …
ehartford commentedon Oct 27, 2026
Fixed on main in 0dc5a25 (#2750), delegated as D163: §9.7 now states the arm rule (
pattern [if guard] => body, body inline, indented or braced after=>); §29.13 excepts match arms from the:/{introducer rule; §30.4'sMATCH_ARMtakes anARM_BODY; §30.8 drops match arms from the colon constructs. No compiler behavior changes — the words now state what the compiler enforces. Pinned by behav_2744_match_arm_three_body_forms and err_2744_match_arm_colon_body. The wording is delegated under D98 (90%: the rule content is the confirmed compiler behavior), so veto or reword freely.