From dff3864a06743e22cce0196933e75696f45c66a9 Mon Sep 17 00:00:00 2001 From: Michiel Borkent Date: Thu, 17 Oct 2024 20:54:08 +0200 Subject: [PATCH] doseq errors --- src/sci/impl/doseq_macro.cljc | 27 ++++++++++++++++++--------- test/sci/error_test.cljc | 6 ++++-- 2 files changed, 22 insertions(+), 11 deletions(-) diff --git a/src/sci/impl/doseq_macro.cljc b/src/sci/impl/doseq_macro.cljc index 9a385c5d..5f1b169a 100644 --- a/src/sci/impl/doseq_macro.cljc +++ b/src/sci/impl/doseq_macro.cljc @@ -15,7 +15,8 @@ (defn expand-doseq [expr _ seq-exprs & body] (assert-args seq-exprs body) - (let [step (fn step [recform exprs] + (let [loc (meta expr) + step (fn step [recform exprs] (if-not exprs [true `(~'do ~@body)] (let [k (first exprs) @@ -48,19 +49,27 @@ steppair-chunk (step recform-chunk (nnext exprs)) subform-chunk (steppair-chunk 1)] [true - `(~allowed-loop [~seq- (seq ~v), ~chunk- nil, + `(~allowed-loop [~seq- ~(with-meta `(seq ~v) + loc) ~chunk- nil, ~count- 0, ~i- 0] (if (< ~i- ~count-) - (let [~k (nth ~chunk- ~i-)] - ~subform-chunk - ~@(when needrec [recform-chunk])) + ~(with-meta + `(let [~k (nth ~chunk- ~i-)] + ~subform-chunk + ~@(when needrec [recform-chunk])) + loc) (let [~seq- (seq ~seq-)] (~'when ~seq- (if (chunked-seq? ~seq-) (let [c# (chunk-first ~seq-)] (~allowed-recur (chunk-rest ~seq-) c# (int (count c#)) (int 0))) - (let [~k (first ~seq-)] - ~subform - ~@(when needrec [recform])))))))])))))] - (nth (step nil (seq seq-exprs)) 1))) + + ~(with-meta + `(let [~k (first ~seq-)] + ~subform + ~@(when needrec [recform])) + loc))))))]))))) + ret (nth (step nil (seq seq-exprs)) 1)] + ;; (prn :ret ret) + ret)) diff --git a/test/sci/error_test.cljc b/test/sci/error_test.cljc index 3d7d929e..bdf283cf 100644 --- a/test/sci/error_test.cljc +++ b/test/sci/error_test.cljc @@ -180,7 +180,7 @@ (is (let [res @(future (invoke-ex-fn f))] (is (= {:line 1 :column 13} (select-keys res [:line :column]))))))))) -(deftest let-test +(deftest destructure-test (doseq [[snippet [line col]] [["(str (let [[a] 1] a))" [1 6]] ["(str (for [[a] [0]] :foo))" [1 6]] @@ -189,7 +189,9 @@ ["(str (if-let [[a] 0] a))" [1 6]] ["(str (when-let [[a] 0] a))" [1 6]] ["(str (if-some [[a] 0] a))" [1 6]] - ["(str (when-some [[a] 0] a))" [1 6]]]] + ["(str (when-some [[a] 0] a))" [1 6]] + ["(str (doseq [a 0] a))" [1 6]] + ["(str (doseq [[a] [0]] a))" [1 6]]]] (try (sci.core/eval-string snippet) (is false)