From 6fff41d9dd903401f8cd8d6eb880dc5a8c841b48 Mon Sep 17 00:00:00 2001 From: Michiel Borkent Date: Tue, 9 Feb 2021 20:33:56 +0100 Subject: [PATCH] [#529] if with falsy literal returns nil --- CHANGELOG.md | 6 ++++++ resources/SCI_VERSION | 2 +- src/sci/impl/analyzer.cljc | 2 +- test/sci/core_test.cljc | 2 ++ 4 files changed, 10 insertions(+), 2 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index d95db64f..2d342845 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -2,6 +2,12 @@ For a list of breaking changes, check [here](#breaking-changes) +## v0.2.3 + +### Enhancements / fixes + +- if with falsy literal returns nil [#529](https://github.com/borkdude/sci/issues/529) + ## v0.2.2 ### Enhancements / fixes diff --git a/resources/SCI_VERSION b/resources/SCI_VERSION index 70899e75..71790396 100644 --- a/resources/SCI_VERSION +++ b/resources/SCI_VERSION @@ -1 +1 @@ -0.2.3-SNAPSHOT +0.2.3 diff --git a/src/sci/impl/analyzer.cljc b/src/sci/impl/analyzer.cljc index 001a59c3..400cbf6d 100644 --- a/src/sci/impl/analyzer.cljc +++ b/src/sci/impl/analyzer.cljc @@ -474,7 +474,7 @@ 3 (let [condition (nth children 0) then (nth children 1) else (nth children 2)] - (cond (not condition) nil + (cond (not condition) else (constant? condition) then :else (ctx-fn (fn [ctx] diff --git a/test/sci/core_test.cljc b/test/sci/core_test.cljc index db8cd4eb..1a2172f8 100644 --- a/test/sci/core_test.cljc +++ b/test/sci/core_test.cljc @@ -50,6 +50,8 @@ (testing "if and when" (is (= 1 (eval* 0 '(if (zero? *in*) 1 2)))) (is (= 2 (eval* 1 '(if (zero? *in*) 1 2)))) + (is (= 10 (eval* "(if true 10 20)"))) + (is (= 20 (eval* "(if false 10 20)"))) (is (thrown-with-msg? #?(:clj Exception :cljs js/Error) #"Too few arguments to if" (eval* '(if)))) (is (thrown-with-msg? #?(:clj Exception :cljs js/Error) #"Too few arguments to if"