~technomancy/fennel

fix match not handling false pattern correctly v1 APPLIED

Andrey Listopadov: 1
 fix match not handling false pattern correctly

 2 files changed, 10 insertions(+), 3 deletions(-)
Export patchset (mbox)
How do I use this?

Copy & paste the following snippet into your terminal to import this patchset into git:

curl -s https://lists.sr.ht/~technomancy/fennel/patches/20554/mbox | git am -3
Learn more about email & git
View this thread in the archives

[PATCH] fix match not handling false pattern correctly Export this patch

---
 src/fennel/macros.fnl | 6 ++++--
 test/macro.fnl        | 7 ++++++-
 2 files changed, 10 insertions(+), 3 deletions(-)

diff --git a/src/fennel/macros.fnl b/src/fennel/macros.fnl
index b78dad0..ec9f4c7 100644
--- a/src/fennel/macros.fnl
+++ b/src/fennel/macros.fnl
@@ -369,8 +369,10 @@ introduce for the duration of the body if it does match."
        seconds []
        res []]
    (for [i 1 (length seq) 2]
      (table.insert firsts (or (. seq i) 'nil))
      (table.insert seconds (or (. seq (+ i 1)) 'nil)))
      (let [first (. seq i)
            second (. seq (+ i 1))]
        (table.insert firsts (if (not= nil first) first 'nil))
        (table.insert seconds (if (not= nil second) second 'nil))))
    (each [i v1 (ipairs firsts)]
      (let [v2 (. seconds i)]
        (if (not= nil v2)
diff --git a/test/macro.fnl b/test/macro.fnl
index 76e08b6..3a295e3 100644
--- a/test/macro.fnl
+++ b/test/macro.fnl
@@ -199,7 +199,12 @@
                  (where tbl (. tbl :sieze)) :siezed)" :siezed
               "(match {:sieze :him}
                  (where tbl tbl.sieze tbl.no) :no
                  (where tbl tbl.sieze (= tbl.sieze :him)) :siezed2)" :siezed2}]
                  (where tbl tbl.sieze (= tbl.sieze :him)) :siezed2)" :siezed2
               "(match false false false true)" false
               "(match nil false false true)" true
               "(match true (where (or nil false true)) :ok :not-ok)" :ok
               "(match false (where (or nil false true)) :ok :not-ok)" :ok
               "(match nil (where (or nil false true)) :ok :not-ok)" :ok}]
    (each [code expected (pairs cases)]
      (l.assertEquals (fennel.eval code {:correlate true}) expected code))))

-- 
2.29.2
Nice catch; thanks. Applied and pushed!

-Phil