mirror of
https://github.com/janet-lang/janet
synced 2025-12-13 20:18:06 +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]
|
[body catch]
|
||||||
(assert (and (not (empty? catch)) (indexed? (catch 0))) "the first element of `catch` must be a tuple or array")
|
(assert (and (not (empty? catch)) (indexed? (catch 0))) "the first element of `catch` must be a tuple or array")
|
||||||
(let [[err fib] (catch 0)
|
(let [[err fib] (catch 0)
|
||||||
r (or err (gensym))
|
r (gensym)
|
||||||
f (or fib (gensym))]
|
f (gensym)]
|
||||||
~(let [,f (,fiber/new (fn :try [] ,body) :ie)
|
~(let [,f (,fiber/new (fn :try [] ,body) :ie)
|
||||||
,r (,resume ,f)]
|
,r (,resume ,f)]
|
||||||
(if (,= (,fiber/status ,f) :error)
|
(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))))
|
,r))))
|
||||||
|
|
||||||
(defmacro with-syms
|
(defmacro with-syms
|
||||||
|
|||||||
Reference in New Issue
Block a user