From 59a242e393aed3c9b4afb6cf7367baec56b5e067 Mon Sep 17 00:00:00 2001 From: benesjan Date: Tue, 3 Mar 2026 01:46:22 +0000 Subject: [PATCH] docs(claude): add Noir early return idiom to CLAUDE.md Document that early `return` is not supported in Noir and show the idiomatic if/else pattern to use instead. Co-Authored-By: Claude Opus 4.6 --- noir-projects/aztec-nr/CLAUDE.md | 1 + 1 file changed, 1 insertion(+) diff --git a/noir-projects/aztec-nr/CLAUDE.md b/noir-projects/aztec-nr/CLAUDE.md index b0f2f2bd1553..0f249d517fa2 100644 --- a/noir-projects/aztec-nr/CLAUDE.md +++ b/noir-projects/aztec-nr/CLAUDE.md @@ -7,6 +7,7 @@ ## Noir Idioms - Use `panic("message")` instead of `assert(false, "message")` for unconditional failures. `panic` returns the parent function's return type, making it usable in expression position (e.g. in if/else branches). Even when the return type doesn't matter, `panic` is the idiomatic choice. +- **Early `return` is not supported in Noir.** You cannot use `return` or `return value` to exit a function early. Instead, restructure the code using `if/else` branches so that all paths lead to the end of the function with a single return expression. For example, instead of `if cond { return None; } ... Some(result)`, write `if cond { Option::none() } else { ... Option::some(result) }`. ## Doc Comments