Skip to content

Commit

Permalink
Fix CTYP-60. Absent keys in map are checked properly.
Browse files Browse the repository at this point in the history
  • Loading branch information
frenchy64 committed Sep 15, 2013
1 parent 6619327 commit 0e6d4c4
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 4 deletions.
15 changes: 11 additions & 4 deletions src/main/clojure/clojure/core/typed/subtype.clj
Expand Up @@ -350,20 +350,27 @@
;eg. {:a 1, :b 2, :c 3} <: {:a 1, :b 2} ;eg. {:a 1, :b 2, :c 3} <: {:a 1, :b 2}
(and (r/HeterogeneousMap? s) (and (r/HeterogeneousMap? s)
(r/HeterogeneousMap? t)) (r/HeterogeneousMap? t))
(let [{ltypes :types labsent :absent-keys :as s} s (let [; convention: prefix things on left with l, right with r
{ltypes :types labsent :absent-keys :as s} s
{rtypes :types rabsent :absent-keys :as t} t] {rtypes :types rabsent :absent-keys :as t} t]
(if (and ; if t is complete, s must be complete (if (and ; if t is complete, s must be complete
(if (c/complete-hmap? t) (if (c/complete-hmap? t)
(c/complete-hmap? s) (c/complete-hmap? s)
true) true)
; all absent keys in t should be absent in s ; all absent keys in t should be absent in s
(or (empty? (set/difference rabsent labsent)) (every? identity
(c/complete-hmap? s)) (for [rabsent-key rabsent]
; Subtyping is good if rabsent-key is:
; 1. Absent in s
; 2. Not present in s, but s is complete
(or ((set labsent) rabsent-key)
(when (c/complete-hmap? s)
(not ((set (keys ltypes)) rabsent-key))))))
; all present keys in t should be present in s ; all present keys in t should be present in s
(every? identity (every? identity
(map (fn [[k v]] (map (fn [[k v]]
(when-let [t (get ltypes k)] (when-let [t (get ltypes k)]
(subtype t v))) (subtype? t v)))
rtypes))) rtypes)))
*sub-current-seen* *sub-current-seen*
(fail! s t))) (fail! s t)))
Expand Down
9 changes: 9 additions & 0 deletions src/test/clojure/clojure/core/typed/test/core.clj
Expand Up @@ -1918,6 +1918,15 @@
(is (cf (map inc [1 2 3]) (is (cf (map inc [1 2 3])
(clojure.core.typed/NonEmptyLazySeq Number)))) (clojure.core.typed/NonEmptyLazySeq Number))))


;CTYP-60
(deftest absent-keys-test
(is (not (sub? (HMap :mandatory {:a String}
:complete? true)
(HMap :absent-keys #{:a}))))
(is
(u/top-level-error-thrown?
(cf {:a "a"} (HMap :absent-keys #{:a})))))

;(reset-caches) ;(reset-caches)


;(chk/abstract-result ;(chk/abstract-result
Expand Down

0 comments on commit 0e6d4c4

Please sign in to comment.