From 8c79015b40ee2dc592e964abcdb21dfa414828c8 Mon Sep 17 00:00:00 2001 From: gilch Date: Wed, 27 Jun 2018 22:37:40 -0600 Subject: [PATCH] Fix let rebind bug. --- hy/contrib/walk.hy | 6 ++++-- tests/native_tests/contrib/walk.hy | 9 +++++++++ 2 files changed, 13 insertions(+), 2 deletions(-) diff --git a/hy/contrib/walk.hy b/hy/contrib/walk.hy index f7d5626..6ee12b2 100644 --- a/hy/contrib/walk.hy +++ b/hy/contrib/walk.hy @@ -305,6 +305,7 @@ as can nested let forms. (macro-error bindings "let bindings must be paired")) (setv g!let (gensym 'let) replacements (OrderedDict) + keys [] values []) (defn expander [symbol] (.get replacements symbol symbol)) @@ -315,10 +316,11 @@ as can nested let forms. (macro-error k "binding target may not contain a dot"))) (.append values (symbolexpand (macroexpand-all v &name) expander)) - (assoc replacements k `(get ~g!let ~(name k)))) + (.append keys `(get ~g!let ~(name k))) + (assoc replacements k (last keys))) `(do (setv ~g!let {} - ~@(interleave (.values replacements) values)) + ~@(interleave keys values)) ~@(symbolexpand (macroexpand-all body &name) expander))) diff --git a/tests/native_tests/contrib/walk.hy b/tests/native_tests/contrib/walk.hy index 2156c3e..730fd45 100644 --- a/tests/native_tests/contrib/walk.hy +++ b/tests/native_tests/contrib/walk.hy @@ -329,3 +329,12 @@ 3)) (assert (= b 3)) (assert (= c 3)))) + +(defn test-let-rebind [] + (let [x "foo" + y "bar" + x (+ x y) + y (+ y x) + x (+ x x)] + (assert (= x "foobarfoobar")) + (assert (= y "barfoobar"))))