Issue #912: A catch block that begins with an arm is a match over error (ADR-catch-1)

Open and answer this issue on GitHub.

ready · opened 2026-10-28 · updated 2026-10-28 · 0 comments

What this is

A handler that tells failures apart writes catch { match error { … } }, two blocks one inside the other. ADR-catch-1 decides a short form: a catch block whose first item is an arm is that match:

let re = regex::dynamic(p) catch {
    regex::Error => {
        eprintln(f"{error}")
        return
    }
    else => throw error
}

Specification: Part I 7, the paragraph after a match over error is complete….

History

Came up on 2026-10-28 while building #673 step 1: catching regex::Error by its name showed that ADR-357 (a type named by its bare name or path covers that member of the error set) was accepted but not built, which is being built now (brief docs/briefs/b673b-catch-by-struct-type.md). The owner found the nested catch { match error { … } } heavy and asked for a shorter form that keeps every catch written today. Options weighed in the record: arms directly in the block (chosen), catch match, Java/Swift clauses per type, a new keyword.

Decision in short

To build

Needs ADR-357 built (D1 and D5).

  1. Parser: a catch block whose first item is pattern => parses as arms; the result is the same tree as catch { match error { … } }, so checker and lowering need nothing new. A block that mixes statements and arms is refused where the form changes, with a message that names the two forms.
  2. Tests in Nikaia (tests/compiler/tests/): the short form with one type, with two types each named, with else => throw error; an incomplete short form refused with NK1151 (.stderr); a fatal error passing a short form that does not name it; a mixed block refused (.stderr); the long form unchanged beside it.
  3. Guide: the error-handling chapter shows the short form beside the long one.

The commit that builds step 3 says Fixes #<this issue>.

Back to Open Issues