<< Back to previous view

[CTYP-61] assoc derives imprecise type when optional attributes present Created: 15/Sep/13  Updated: 25/Sep/13  Resolved: 20/Sep/13

Status: Closed
Project: core.typed
Component/s: None
Affects Version/s: None
Fix Version/s: None

Type: Defect Priority: Major
Reporter: Chris Spencer Assignee: Ambrose Bonnaire-Sergeant
Resolution: Completed Votes: 0
Labels: None


 Description   

"Real world" use case, removing the optional forename makes things work as expected:

Unable to find source-code formatter for language: clojure. Available languages are: javascript, sql, xhtml, actionscript, none, html, xml, java
(def-alias TUser (HMap :mandatory {:group String}
                       :optional {:forename String}
                  ))
(def-alias TAdmin (HMap :mandatory {:group (Value "admin")}
                        :optional {:forename String}
                  ))

(ann my-user TUser)
(def my-user {:group "whee"})

(ann my-admin TAdmin)
(def my-admin (assoc my-user :group "admin"))

Smaller test case:

Unable to find source-code formatter for language: clojure. Available languages are: javascript, sql, xhtml, actionscript, none, html, xml, java
(cf (assoc
      (ann-form {} (HMap :optional {:a Any}))
      :b "v")
    (HMap :mandatory {:b (Value "v")} :optional {:a Any}))


 Comments   
Comment by Chris Spencer [ 15/Sep/13 11:03 AM ]

s/attributes/keys

Comment by Chris Spencer [ 15/Sep/13 3:07 PM ]

Ah i see this in a TODO in check.clj#L2120

Comment by Chris Spencer [ 15/Sep/13 4:28 PM ]

I had a quick stab at this, just to try and learn the code a bit:
https://github.com/c-spencer/core.typed/commit/c675662004b03241df596978d897cb254973bd63

Just runs the original inner update over the union. I moved the inner part out to a supporting function just to make things clearer for myself..

Passes some cursory checks, and I added a couple of simple test cases in the following commit.

user=> (cf (assoc (ann-form {} (HMap :optional {:a Any})) :b "v"))
[(U (HMap :mandatory {:b (Value "v"), :a Any}) (HMap :mandatory {:b (Value "v")} :absent-keys #{:a})) {:then tt, :else ff}]
user=> (cf (assoc (ann-form {} (HMap :optional {:b Any})) :b "v"))
[(HMap :mandatory {:b (Value "v")}) {:then tt, :else ff}]
Comment by Ambrose Bonnaire-Sergeant [ 20/Sep/13 8:42 PM ]

Fixed in 0.2.8

https://github.com/clojure/core.typed/blob/74d24b8228c65b4d3158ec716830549fa9e1cd75/src/test/clojure/clojure/core/typed/test/core.clj#L2011

Generated at Mon Dec 22 20:20:53 CST 2014 using JIRA 4.4#649-r158309.