Skip to content

Commit f1ec0cc

Browse files
committed
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.
1 parent 98265f0 commit f1ec0cc

File tree

1 file changed

+6
-3
lines changed

1 file changed

+6
-3
lines changed

src/boot/boot.janet

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -348,12 +348,15 @@
348348
[body catch]
349349
(assert (and (not (empty? catch)) (indexed? (catch 0))) "the first element of `catch` must be a tuple or array")
350350
(let [[err fib] (catch 0)
351-
r (or err (gensym))
352-
f (or fib (gensym))]
351+
r (gensym)
352+
f (gensym)]
353353
~(let [,f (,fiber/new (fn :try [] ,body) :ie)
354354
,r (,resume ,f)]
355355
(if (,= (,fiber/status ,f) :error)
356-
(do ,;(tuple/slice catch 1))
356+
(do
357+
,(if err ~(def ,err ,r))
358+
,(if fib ~(def ,fib ,f))
359+
,;(tuple/slice catch 1))
357360
,r))))
358361

359362
(defmacro with-syms

0 commit comments

Comments
 (0)