Skip to content

Commit 50b9c45

Browse files
authored
Fix a bug where condp could throw an exception in some cases (#1195)
Fixes #1194
1 parent 5ef8525 commit 50b9c45

File tree

3 files changed

+22
-10
lines changed

3 files changed

+22
-10
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
1616
### Fixed
1717
* Fix a bug in `defn` where the `attr-map?` and function metdata were merged into a seq instead of a map, causing `macroexpand` to fail in some cases (#1186)
1818
* Fix a bug where `basilisp.process/exec` threw an exception when inheriting the stdout stream from the current process (#1190)
19+
* Fix a bug where `condp` threw an exception in certain cases (#1194)
1920

2021
## [v0.3.5]
2122
### Changed

src/basilisp/core.lpy

Lines changed: 16 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -3573,16 +3573,22 @@
35733573
(let [result (first remaining)
35743574
remaining (rest remaining)]
35753575
(cond
3576-
(not (seq remaining)) `(throw
3577-
(python/ValueError
3578-
(str "Expected result expression for condp " {:test ~test-expr})))
3579-
(= result :>>) `(let [res# ~(list pred test-expr expr)]
3580-
(if res#
3581-
(~(first remaining) res#)
3582-
(condp ~pred ~expr ~@(rest remaining))))
3583-
:else `(if ~(list pred test-expr expr)
3584-
~result
3585-
(condp ~pred ~expr ~@remaining))))
3576+
(= result :>>) `(let [res# ~(list pred test-expr expr)]
3577+
(if res#
3578+
(~(first remaining) res#)
3579+
(condp ~pred ~expr ~@(rest remaining))))
3580+
(seq remaining) `(if ~(list pred test-expr expr)
3581+
~result
3582+
(condp ~pred ~expr ~@remaining))
3583+
(and result
3584+
(not (seq remaining))) `(if ~(list pred test-expr expr)
3585+
~result
3586+
(throw
3587+
(python/ValueError
3588+
(str "Expected result expression for condp " {:test ~test-expr}))))
3589+
:else `(throw
3590+
(python/ValueError
3591+
(str "Expected result expression for condp " {:test ~test-expr})))))
35863592
test-expr))))
35873593

35883594
(defmacro declare

tests/basilisp/test_core_macros.lpy

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -416,6 +416,11 @@
416416
(deftest condp-test
417417
(testing "condp result value"
418418
(is (= :a (condp = "a" :a)))
419+
(is (= :a (condp = "a"
420+
"a" :a)))
421+
(is (= :a (condp = "a"
422+
"a" :a
423+
:b)))
419424
(is (= :a (condp = "a"
420425
"b" :b
421426
:a)))

0 commit comments

Comments
 (0)