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-value (interpret-ast if-expr ctx)
if-match (match if-pattern if-value ctx)
success (:success if-match)]
(if success (if success
(do (interpret-ast then-expr (volatile! (merge (:ctx if-match) {:parent ctx})))
(vswap! ctx update-ctx (:ctx match)) (if (:code if-match)
value) (throw (ex-info (:reason if-match) {:ast if-ast}))
(if (:code match) (interpret-ast else-expr ctx)))))
(throw (ex-info (:reason match) {:ast ast}))
false))))
(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)