Fix bug where if let leaked context

This commit is contained in:
Scott Richmond 2022-11-03 17:19:46 -04:00
parent 06c1b55b62
commit 01d7dc0ab1

View File

@ -203,29 +203,29 @@
value)) value))
(defn- interpret-if-let [ast ctx] (defn- interpret-if-let [ast ctx]
(let [pattern (:pattern ast) (let [if-ast (:if ast)
expr (:expr ast) then-expr (:then ast)
value (interpret-ast expr ctx) else-expr (:else ast)
match (match pattern value ctx) if-pattern (:pattern if-ast)
success (:success match)] if-expr (:expr if-ast)
(if success if-value (interpret-ast if-expr ctx)
(do if-match (match if-pattern if-value ctx)
(vswap! ctx update-ctx (:ctx match)) success (:success if-match)]
value) (if success
(if (:code match) (interpret-ast then-expr (volatile! (merge (:ctx if-match) {:parent ctx})))
(throw (ex-info (:reason match) {:ast ast})) (if (:code if-match)
false)))) (throw (ex-info (:reason if-match) {:ast if-ast}))
(interpret-ast else-expr ctx)))))
(defn- interpret-if [ast ctx] (defn- interpret-if [ast ctx]
(let [if-expr (:if ast) (let [if-expr (:if ast)
then-expr (:then ast) then-expr (:then ast)
else-expr (:else ast) else-expr (:else ast)]
if-value (if (= (::ast/type if-expr) ::ast/let) (if (= (::ast/type if-expr) ::ast/let)
(interpret-if-let if-expr ctx) (interpret-if-let ast ctx)
(interpret-ast if-expr ctx))] (if (interpret-ast if-expr ctx)
(if if-value (interpret-ast then-expr ctx)
(interpret-ast then-expr ctx) (interpret-ast else-expr ctx)))))
(interpret-ast else-expr ctx))))
(defn- interpret-match [ast ctx] (defn- interpret-match [ast ctx]
(let [match-expr (:expr ast) (let [match-expr (:expr ast)