<< Back to previous view

[CLJS-464] `get-in` not behaving like Clojure when accessing non-existing inner maps Created: 26/Jan/13  Updated: 27/Jul/13  Resolved: 28/Jan/13

Status: Closed
Project: ClojureScript
Component/s: None
Affects Version/s: None
Fix Version/s: None

Type: Defect Priority: Major
Reporter: Roman Gonzalez Assignee: Unassigned
Resolution: Completed Votes: 0
Labels: bug
Environment:

Gentoo 64, oracle-jvm


Attachments: Text File get-in-fix.patch    

 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



 Comments   
Comment by Roman Gonzalez [ 26/Jan/13 11:01 PM ]

Code and Test patch v1

Comment by David Nolen [ 27/Jan/13 5:25 PM ]

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

Comment by Roman Gonzalez [ 28/Jan/13 10:06 PM ]

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.

Comment by David Nolen [ 28/Jan/13 10:39 PM ]

fixed, http://github.com/clojure/clojurescript/commit/2b21e9d5b09cdd09f2831d11810fa2c5ae4f14b1

Generated at Fri Aug 01 21:39:48 CDT 2014 using JIRA 4.4#649-r158309.