Diagnostics
The parser validates the shape of a when and its completion clauses, rejecting
malformed forms with three dedicated diagnostics instead of a generic
"Expected expression" cascade.
ARIA-WHEN-001 — stray then / end
A then or end block must follow a when body. Writing one on its own is an
error:
then { // error: ARIA-WHEN-001
// ...
}
error: ARIA-WHEN-001: 'then' block has no preceding 'when' —
'then'/'end' clauses may only follow a 'when' loop body
Fix: attach the block to a when, or remove it if it was a stray paste.
ARIA-WHEN-002 — duplicate then / end
A when may carry at most one then and one end. A second of either is
rejected:
when (i < 1i32) {
i = i + 1i32;
} then {
// ...
} then { // error: ARIA-WHEN-002
// ...
}
error: ARIA-WHEN-002: duplicate 'then' block — a 'when' may have at most
one 'then' clause
Fix: merge the two blocks into one, or move the extra logic after the
when.
ARIA-WHEN-003 — then after end
The clauses are ordered: then comes before end. Writing them in the wrong
order is rejected:
when (i < 1i32) {
i = i + 1i32;
} end {
// ...
} then { // error: ARIA-WHEN-003
// ...
}
error: ARIA-WHEN-003: 'then' block must precede 'end' —
write 'when (...) { } then { } end { }'
Fix: swap the blocks so then precedes end.
Why dedicated diagnostics
Before v0.39.5 these mistakes surfaced as a confusing chain of parser errors —
the stray keyword was parsed as the start of an expression, producing
"Expected expression" followed by a cascade of unrelated messages. The
ARIA-WHEN-* codes point straight at the real problem and tell you the fix.