Skip to content

Commit ddc65d6

Browse files
authored
Fixed inconsistent behaviour with basilisp.core/with body (#982)
Hi, could you please consider patch to fix the inconsistent behaviour of the `basilisp.core/with` `body` argument. It fixes #981. Tests added. Thanks --------- Co-authored-by: ikappaki <[email protected]>
1 parent b8201b3 commit ddc65d6

File tree

3 files changed

+17
-2
lines changed

3 files changed

+17
-2
lines changed

CHANGELOG.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,9 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
1212
* Improved on the nREPL server exception messages by matching that of the REPL user friendly format (#968)
1313
* Types created via `deftype` and `reify` may declare supertypes as abstract (taking precedence over true `abc.ABC` types) and specify their member list using `^:abstract-members` metadata (#942)
1414

15+
### Fixed
16+
* Fixed inconsistent behavior with `basilisp.core/with` when the `body` contains more than one form (#981)
17+
1518
### Removed
1619
* Removed `python-dateutil` and `readerwriterlock` as dependencies, switching to standard library components instead (#976)
1720

src/basilisp/core.lpy

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3778,7 +3778,7 @@
37783778
[(concat
37793779
(list 'with (vec (nthrest bindings 2)))
37803780
body)]
3781-
body)]
3781+
(list (concat '(do) body)))]
37823782
res#)
37833783
(catch python/Exception e#
37843784
(vreset! hit-except# true)

tests/basilisp/test_core_macros.lpy

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
(ns tests.basilisp.test-core-macros
2-
(:import inspect os socket tempfile)
2+
(:import contextlib inspect os socket tempfile)
33
(:require
44
[basilisp.test :refer [deftest is testing]]))
55

@@ -471,6 +471,18 @@
471471
(os/close fh)
472472
(os/unlink filename)))))
473473

474+
(testing "with multiple body forms"
475+
(let [v* (volatile! nil)]
476+
(is (= 2 (with [_ (contextlib/nullcontext)]
477+
(vreset! v* 5) (vswap! v* inc) 2)))
478+
(is (= 6 @v*)))
479+
480+
(let [v* (volatile! nil)]
481+
(is (= 3 (with [_ (contextlib/nullcontext)
482+
_ (contextlib/nullcontext)]
483+
(vreset! v* 6) (vswap! v* inc) 3)))
484+
(is (= 7 @v*))))
485+
474486
(testing "exceptions"
475487
(is (thrown? python/FloatingPointError
476488
(with [sock (socket/socket socket/AF_INET socket/SOCK_STREAM)]

0 commit comments

Comments
 (0)