mirror of
https://github.com/janet-lang/janet
synced 2025-12-12 19:48:07 +00:00
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.
This commit is contained in:
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user