ClojureScript

`get-in` not behaving like Clojure when accessing non-existing inner maps

Details

  • Type: Defect Defect
  • Status: Closed Closed
  • Priority: Major Major
  • Resolution: Completed
  • Affects Version/s: None
  • Fix Version/s: None
  • Component/s: None
  • Labels:
  • Environment:
    Gentoo 64, oracle-jvm

Description

In Clojurescript:
(get-in {:a {:b 1}} [:a :b :c])
=> Error: 1 is not an instance of ILookup

In Clojure:
(get-in {:a {:b 1}} [:a :b :c])
=> nil

Activity

Hide
Roman Gonzalez added a comment -

Code and Test patch v1

Show
Roman Gonzalez added a comment - Code and Test patch v1
Hide
David Nolen added a comment -

Isn't this a duplicate of CLJS-458? That's been fixed in master.

Show
David Nolen added a comment - Isn't this a duplicate of CLJS-458? That's been fixed in master.
Hide
Roman Gonzalez added a comment -

Hey David,

Thanks for your prompt reply, I tested latest version of github's master with the test-case I added and got this error.

```shell
Testing with V8
out/core-advanced-test.js:1: Error: No protocol method ILookup.-lookup defined for type number: 2
function d(a){throw a;}var e=void 0,f=!0,g=null,h=!1;function aa(){return func
^
Error: No protocol method ILookup.-lookup defined for type number: 2
at Error (<anonymous>)
at t (out/core-advanced-test.js:5:962)
at Function.ab [as c] (out/core-advanced-test.js:11:239)
at Function.wd [as c] (out/core-advanced-test.js:49:60)
at Function.Dc [as h] (out/core-advanced-test.js:36:58)
at Nk.l.Da (out/core-advanced-test.js:176:128)
at Function.Bb [as h] (out/core-advanced-test.js:16:342)
at Function.Ye [as h] (out/core-advanced-test.js:65:210)
at Function.Lj [as c] (out/core-advanced-test.js:164:27)
at Eu (out/core-advanced-test.js:602:398)

SPIDERMONKEY_HOME not set, skipping SpiderMonkey tests
JSC_HOME not set, skipping JavaScriptCore tests
Tested with 1 out of 3 possible js targets
```

The test case is:

```gitdiff
diff --git a/test/cljs/cljs/core_test.cljs b/test/cljs/cljs/core_test.cljs
index 2d1d2f3..bf3f7bb 100644
— a/test/cljs/cljs/core_test.cljs
+++ b/test/cljs/cljs/core_test.cljs
@@ -656,6 +656,7 @@
(assert (= 1 (get-in [{:foo 1}, {:foo 2}] [0 :foo])))
(assert (= 4 (get-in [{:foo 1 :bar [{:baz 1}, {:buzz 2}]}, {:foo 3 :bar [{:baz 3}, {:buzz 4}]}]
[1 :bar 1 :buzz])))
+ (assert (nil? (get-in {:foo {:bar 2}} [:foo :bar :baz])))

;; arrays
(let [a (to-array [1 2 3])]
```

In case github's master is not the latest one, and test works on master, please discard this message.

Cheers.

Show
Roman Gonzalez added a comment - Hey David, Thanks for your prompt reply, I tested latest version of github's master with the test-case I added and got this error. ```shell Testing with V8 out/core-advanced-test.js:1: Error: No protocol method ILookup.-lookup defined for type number: 2 function d(a){throw a;}var e=void 0,f=!0,g=null,h=!1;function aa(){return func ^ Error: No protocol method ILookup.-lookup defined for type number: 2 at Error (<anonymous>) at t (out/core-advanced-test.js:5:962) at Function.ab [as c] (out/core-advanced-test.js:11:239) at Function.wd [as c] (out/core-advanced-test.js:49:60) at Function.Dc [as h] (out/core-advanced-test.js:36:58) at Nk.l.Da (out/core-advanced-test.js:176:128) at Function.Bb [as h] (out/core-advanced-test.js:16:342) at Function.Ye [as h] (out/core-advanced-test.js:65:210) at Function.Lj [as c] (out/core-advanced-test.js:164:27) at Eu (out/core-advanced-test.js:602:398) SPIDERMONKEY_HOME not set, skipping SpiderMonkey tests JSC_HOME not set, skipping JavaScriptCore tests Tested with 1 out of 3 possible js targets ``` The test case is: ```gitdiff diff --git a/test/cljs/cljs/core_test.cljs b/test/cljs/cljs/core_test.cljs index 2d1d2f3..bf3f7bb 100644 — a/test/cljs/cljs/core_test.cljs +++ b/test/cljs/cljs/core_test.cljs @@ -656,6 +656,7 @@ (assert (= 1 (get-in [{:foo 1}, {:foo 2}] [0 :foo]))) (assert (= 4 (get-in [{:foo 1 :bar [{:baz 1}, {:buzz 2}]}, {:foo 3 :bar [{:baz 3}, {:buzz 4}]}] [1 :bar 1 :buzz]))) + (assert (nil? (get-in {:foo {:bar 2}} [:foo :bar :baz]))) ;; arrays (let [a (to-array [1 2 3])] ``` In case github's master is not the latest one, and test works on master, please discard this message. Cheers.

People

Vote (0)
Watch (1)

Dates

  • Created:
    Updated:
    Resolved: