Skip to content

Commit 9cb8da1

Browse files
anmonteirodnolen
authored andcommitted
CLJS-1775: get with nil returns as if get with 0
1 parent f1981a4 commit 9cb8da1

2 files changed

Lines changed: 10 additions & 4 deletions

File tree

src/main/cljs/cljs/core.cljs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1819,7 +1819,7 @@ reduces them without incurring seq initialization"
18191819
(aget o (int k)))
18201820

18211821
(string? o)
1822-
(when (< k (.-length o))
1822+
(when (and (some? k) (< k (.-length o)))
18231823
(aget o (int k)))
18241824

18251825
(native-satisfies? ILookup o)
@@ -1834,12 +1834,12 @@ reduces them without incurring seq initialization"
18341834

18351835
(array? o)
18361836
(if (< k (.-length o))
1837-
(aget o k)
1837+
(aget o (int k))
18381838
not-found)
1839-
1839+
18401840
(string? o)
18411841
(if (< k (.-length o))
1842-
(aget o k)
1842+
(aget o (int k))
18431843
not-found)
18441844

18451845
(native-satisfies? ILookup o)

src/test/cljs/cljs/core_test.cljs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3256,6 +3256,12 @@
32563256
(assoc record :d 4 :e 5)) )
32573257
#{[:a 1] [:b 2] [:c 3] [:d 4] [:e 5]}))))
32583258

3259+
(deftest test-cljs-1775
3260+
(is (nil? (get "foo" nil)))
3261+
(is (= 42 (get {nil 42} nil) 42))
3262+
(is (= (get #js [\h \i] 1.7 :not-found) \i))
3263+
(is (= (get "hi" 1.7 :not-found) \i)))
3264+
32593265
(comment
32603266
;; ObjMap
32613267
;; (let [ks (map (partial str "foo") (range 500))

0 commit comments

Comments
 (0)