1
0
mirror of https://github.com/janet-lang/janet synced 2024-12-27 00:40:26 +00:00
Add binding check for generate verb in loops. The check is present
in other loop verbs.
This commit is contained in:
Calvin Rose 2020-06-21 15:54:31 -05:00
parent 5c364e0f7c
commit 08a3687eb5
2 changed files with 9 additions and 1 deletions

View File

@ -471,10 +471,12 @@
:in (each-template binding object [rest]) :in (each-template binding object [rest])
:iterate (iterate-template binding object rest) :iterate (iterate-template binding object rest)
:generate (with-syms [f s] :generate (with-syms [f s]
(def ds (if (idempotent? binding) binding (gensym)))
~(let [,f ,object] ~(let [,f ,object]
(while true (while true
(def ,binding (,resume ,f)) (def ,ds (,resume ,f))
(if (= :dead (,fiber/status ,f)) (break)) (if (= :dead (,fiber/status ,f)) (break))
,;(if (= ds binding) [] [~(def ,binding ,ds)])
,rest))) ,rest)))
(error (string "unexpected loop verb " verb))))) (error (string "unexpected loop verb " verb)))))

View File

@ -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 string")
(check-jdn @"a buffer") (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) (end-suite)