Skip to content

Commit b9330ec

Browse files
athosstuarthalloway
authored andcommitted
CLJ-1319 Throw on odd arguments to PersistentArrayMap.createAsIfByAssoc
Signed-off-by: Stuart Halloway <[email protected]>
1 parent 87a7d78 commit b9330ec

File tree

2 files changed

+5
-0
lines changed

2 files changed

+5
-0
lines changed

src/jvm/clojure/lang/PersistentArrayMap.java

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -74,6 +74,8 @@ static public PersistentArrayMap createWithCheck(Object[] init){
7474
}
7575

7676
static public PersistentArrayMap createAsIfByAssoc(Object[] init){
77+
if ((init.length & 1) == 1)
78+
throw new IllegalArgumentException(String.format("No value supplied for key: %s", init[init.length-1]));
7779
// If this looks like it is doing busy-work, it is because it
7880
// is achieving these goals: O(n^2) run time like
7981
// createWithCheck(), never modify init arg, and only

test/clojure/test_clojure/data_structures.clj

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1062,6 +1062,9 @@
10621062
{x1 v4a, w5a v4c, v4a z3b, y2 2} [x1 v4a, w5a v4a, w5b v4b,
10631063
v4a z3a, y2 2, v4b z3b, w5c v4c])))
10641064

1065+
(deftest test-array-map-arity
1066+
(is (thrown? IllegalArgumentException
1067+
(array-map 1 2 3))))
10651068

10661069
(deftest test-assoc
10671070
(are [x y] (= x y)

0 commit comments

Comments
 (0)