Skip to content

Commit 02c6d2a

Browse files
mfikesswannodette
authored andcommitted
CLJS-2307: Closure warns on unreachable checked array code
1 parent a15846b commit 02c6d2a

File tree

2 files changed

+19
-14
lines changed

2 files changed

+19
-14
lines changed

src/main/cljs/cljs/core.cljs

Lines changed: 16 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -439,26 +439,28 @@
439439

440440
(defn- checked-aget
441441
([array idx]
442-
(try
443-
(assert (or (array? array) (js/goog.isArrayLike array)))
444-
(assert (number? idx))
445-
(assert (not (neg? idx)))
446-
(assert (< idx (alength array)))
447-
(catch :default e
448-
(maybe-warn e)))
442+
(when-assert
443+
(try
444+
(assert (or (array? array) (js/goog.isArrayLike array)))
445+
(assert (number? idx))
446+
(assert (not (neg? idx)))
447+
(assert (< idx (alength array)))
448+
(catch :default e
449+
(maybe-warn e))))
449450
(unchecked-get array idx))
450451
([array idx & idxs]
451452
(apply checked-aget (checked-aget array idx) idxs)))
452453

453454
(defn- checked-aset
454455
([array idx val]
455-
(try
456-
(assert (or (array? array) (js/goog.isArrayLike array)))
457-
(assert (number? idx))
458-
(assert (not (neg? idx)))
459-
(assert (< idx (alength array)))
460-
(catch :default e
461-
(maybe-warn e)))
456+
(when-assert
457+
(try
458+
(assert (or (array? array) (js/goog.isArrayLike array)))
459+
(assert (number? idx))
460+
(assert (not (neg? idx)))
461+
(assert (< idx (alength array)))
462+
(catch :default e
463+
(maybe-warn e))))
462464
(unchecked-set array idx val))
463465
([array idx idx2 & idxv]
464466
(apply checked-aset (checked-aget array idx) idx2 idxv)))

src/main/clojure/cljs/core.cljc

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2290,6 +2290,9 @@
22902290
~@(mapcat (core/fn [[m c]] `((cljs.core/= ~m ~esym) ~c)) pairs)
22912291
:else ~default)))))
22922292

2293+
(core/defmacro ^:private when-assert [x]
2294+
(core/when *assert* x))
2295+
22932296
(core/defmacro assert
22942297
"Evaluates expr and throws an exception if it does not evaluate to
22952298
logical true."

0 commit comments

Comments
 (0)