<< Back to previous view

[TANAL-112] Reflection in simple catch expression Created: 27/Jul/15  Updated: 27/Jul/15  Resolved: 27/Jul/15

Status: Closed
Project: tools.analyzer
Component/s: None
Affects Version/s: None
Fix Version/s: None

Type: Defect Priority: Critical
Reporter: Nicola Mometto Assignee: Nicola Mometto
Resolution: Completed Votes: 0
Labels: None


 Description   
clojure.tools.analyzer.jvm> (analyze+eval '(try :anything (catch Exception e (.getCause e))))
Reflection warning: 1:50 - reference to field or no args method call getCause cannot be resolved

Report:
https://groups.google.com/forum/#!topic/clojure-core-typed/EJIl01yQhPk

Relevant commits:
https://github.com/clojure/tools.analyzer/commit/1bb4d366cbdae7d2bb9325798fb96e14a3e95a92
https://github.com/clojure/tools.analyzer.jvm/commit/bd985917d6324d27bbd5c10d4dd77291d28790a3



 Comments   
Comment by Nicola Mometto [ 27/Jul/15 6:13 AM ]

https://github.com/clojure/tools.analyzer.jvm/commit/966fe1ff985039bf29d640fbd8bf95ea50aad237





[TANAL-111] location information is wrong when maps are destructured with default values Created: 25/Jul/15  Updated: 26/Jul/15  Resolved: 26/Jul/15

Status: Closed
Project: tools.analyzer
Component/s: None
Affects Version/s: None
Fix Version/s: None

Type: Defect Priority: Major
Reporter: Benedek Fazekas Assignee: Nicola Mometto
Resolution: Declined Votes: 0
Labels: None


 Description   

when analyzing something like:

43 (defn fn-with-default-optmap
44   [{:keys [foo bar] :or {foo "foo"}}]
45   (count foo))

the location information for the nodes representing the map with the defaults is pointing back to the symbols in the keys vector.
if I run something like this in the repl:

(->> (nodes fn-with-default-optmap-ast)
     (filter #(= 44 (-> % :env :line))) 
     (map (juxt :form (comp :column :env) (comp :end-column :env))))

the result as follows:

;; => ([foo 12 16] 
       [(. clojure.lang.RT (clojure.core/get map__22781 :foo "foo")) 12 16] 
       [map__22781 12 16] 
       [:foo 12 16] 
       ["foo" 12 16]
       [bar 16 20] 
       [(. clojure.lang.RT (clojure.core/get map__22781 :bar)) 16 20] 
       [map__22781 16 20]
       [:bar 16 20])

This causes difficulties when find-usages or rename-symbol and other related features are run in tools supported by refactor-nrepl. Please find more information in this bugreport on refactor-nrepl.



 Comments   
Comment by Nicola Mometto [ 26/Jul/15 12:00 PM ]

This is not a bug, it's a consequence of how clojure works and how destructuring is implemented.
The {:keys [foo bar] :or {foo "foo"}} structure doesn't exist after macroexpansion, the two instances of the symbol foo are expanded into a single expression roughly equivalent to

(let [foo (get map :foo "foo")])
, what you are asking is beyond what tools.analyzer can support

Comment by Benedek Fazekas [ 26/Jul/15 5:51 PM ]

fair enough. thanks for checking.





Generated at Sat Aug 01 04:57:15 CDT 2015 using JIRA 4.4#649-r158309.