From 08a3687eb5f31dad27af7d299da98f71d142ad6a Mon Sep 17 00:00:00 2001 From: Calvin Rose Date: Sun, 21 Jun 2020 15:54:31 -0500 Subject: [PATCH] Fix #428 Add binding check for generate verb in loops. The check is present in other loop verbs. --- src/boot/boot.janet | 4 +++- test/suite8.janet | 6 ++++++ 2 files changed, 9 insertions(+), 1 deletion(-) diff --git a/src/boot/boot.janet b/src/boot/boot.janet index 47b4724d..4474a458 100644 --- a/src/boot/boot.janet +++ b/src/boot/boot.janet @@ -471,10 +471,12 @@ :in (each-template binding object [rest]) :iterate (iterate-template binding object rest) :generate (with-syms [f s] + (def ds (if (idempotent? binding) binding (gensym))) ~(let [,f ,object] (while true - (def ,binding (,resume ,f)) + (def ,ds (,resume ,f)) (if (= :dead (,fiber/status ,f)) (break)) + ,;(if (= ds binding) [] [~(def ,binding ,ds)]) ,rest))) (error (string "unexpected loop verb " verb))))) diff --git a/test/suite8.janet b/test/suite8.janet index 9cd6152f..78bc2ed0 100644 --- a/test/suite8.janet +++ b/test/suite8.janet @@ -319,4 +319,10 @@ neldb\0\0\0\xD8\x05printG\x01\0\xDE\xDE\xDE'\x03\0marshal_tes/\x02 (check-jdn "a string") (check-jdn @"a buffer") +# Issue 428 +(var result nil) +(defn f [] (yield {:a :ok})) +(assert-no-error "issue 428 1" (loop [{:a x} :generate (fiber/new f)] (set result x))) +(assert (= result :ok) "issue 428 2") + (end-suite)