From f1ec0cc48b43b972710274be437f3d2ad71e40fc Mon Sep 17 00:00:00 2001 From: Ian Henry Date: Fri, 24 Oct 2025 21:25:44 -0700 Subject: [PATCH] fix try macro hygiene Allow re-using the same symbol for the fiber and error. This allows you to write code like (try (print "hi") ([_ _] (print "oh no"))), fixing a regression introduced in #1605. --- src/boot/boot.janet | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/src/boot/boot.janet b/src/boot/boot.janet index c929cb0e..cc8f3fa0 100644 --- a/src/boot/boot.janet +++ b/src/boot/boot.janet @@ -348,12 +348,15 @@ [body catch] (assert (and (not (empty? catch)) (indexed? (catch 0))) "the first element of `catch` must be a tuple or array") (let [[err fib] (catch 0) - r (or err (gensym)) - f (or fib (gensym))] + r (gensym) + f (gensym)] ~(let [,f (,fiber/new (fn :try [] ,body) :ie) ,r (,resume ,f)] (if (,= (,fiber/status ,f) :error) - (do ,;(tuple/slice catch 1)) + (do + ,(if err ~(def ,err ,r)) + ,(if fib ~(def ,fib ,f)) + ,;(tuple/slice catch 1)) ,r)))) (defmacro with-syms