Skip to content

Commit bcd35a6

Browse files
committed
ASYNC-255 Add guard in alts for write op with nil message
1 parent f0cb33c commit bcd35a6

File tree

3 files changed

+19
-0
lines changed

3 files changed

+19
-0
lines changed

src/main/clojure/cljs/core/async.cljs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -180,6 +180,12 @@
180180
(let [flag (alt-flag)
181181
ports (vec ports) ;; ensure vector for indexed nth
182182
n (count ports)
183+
_ (loop [i 0] ;; check for invalid write op
184+
(when (< i n)
185+
(let [port (nth ports i)]
186+
(when (vector? port)
187+
(assert (some? (port 1)) "can't put nil on channel")))
188+
(recur (unchecked-inc i))))
183189
idxs (random-array n)
184190
priority (:priority opts)
185191
ret

src/main/clojure/clojure/core/async.clj

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -280,6 +280,12 @@ to catch and handle."
280280
(let [flag (alt-flag)
281281
ports (vec ports) ;; ensure vector for indexed nth
282282
n (count ports)
283+
_ (loop [i 0] ;; check for invalid write op
284+
(when (< i n)
285+
(let [port (nth ports i)]
286+
(when (vector? port)
287+
(assert (some? (port 1)) "can't put nil on channel")))
288+
(recur (unchecked-inc i))))
283289
^ints idxs (random-array n)
284290
priority (:priority opts)
285291
ret

src/test/clojure/clojure/core/async_test.clj

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -465,3 +465,10 @@
465465
:ok
466466
(catch AssertionError e
467467
:ko))))))
468+
469+
(deftest test-alts-put-nil-invalid
470+
(is
471+
(thrown? AssertionError
472+
(let [c1 (a/chan)
473+
c2 (a/chan)]
474+
(a/alts!! [c1 [c2 nil]])))))

0 commit comments

Comments
 (0)