From 0903cd8ba4485927cdf4858265fec5e51c816bac Mon Sep 17 00:00:00 2001 From: "Sean T. Allen" Date: Sun, 1 Mar 2026 08:56:32 -0500 Subject: [PATCH] Add \exhaustive\ annotation to exhaustive match blocks Ponyc recently added an \exhaustive\ annotation for match expressions. When present, the compiler will fail compilation if the match is not exhaustive. This protects against future breakage if new variants are added to a union type. --- json/_json_print.pony | 2 +- json/json_doc.pony | 6 +++--- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/json/_json_print.pony b/json/_json_print.pony index e3f3463..f8d9ab4 100644 --- a/json/_json_print.pony +++ b/json/_json_print.pony @@ -29,7 +29,7 @@ primitive _JsonPrint """ var buf = consume buf' - match d + match \exhaustive\ d | let x: Bool => buf.append(x.string()) | let x: None => buf.append("null") | let x: String => diff --git a/json/json_doc.pony b/json/json_doc.pony index b3c2b19..b5a71c9 100644 --- a/json/json_doc.pony +++ b/json/json_doc.pony @@ -72,7 +72,7 @@ class JsonDoc Raise error on invalid or missing value. """ _dump_whitespace() - match _peek_char(context)? + match \exhaustive\ _peek_char(context)? | let c: U8 if (c >= 'a') and (c <= 'z') => _parse_keyword()? | let c: U8 if (c >= '0') and (c <= '9') => _parse_number()? | '-' => _parse_number()? @@ -350,7 +350,7 @@ class JsonDoc while i < 4 do let d = - match _get_char("Unicode escape sequence")? + match \exhaustive\ _get_char("Unicode escape sequence")? | let c: U8 if (c >= '0') and (c <= '9') => c - '0' | let c: U8 if (c >= 'a') and (c <= 'f') => (c - 'a') + 10 | let c: U8 if (c >= 'A') and (c <= 'F') => (c - 'A') + 10 @@ -401,7 +401,7 @@ class JsonDoc // EOF found, is that OK? _last_index = -1 - match eof_context + match \exhaustive\ eof_context | None => return 0 // EOF is allowed | let context: String => // EOF not allowed