Skip to content

Commit

Permalink
fix can't destructure dart maps
Browse files Browse the repository at this point in the history
  • Loading branch information
cgrand committed Nov 8, 2024
1 parent 71b9d9f commit 0e1ef25
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 7 deletions.
23 changes: 16 additions & 7 deletions clj/src/cljd/compiler.cljc
Original file line number Diff line number Diff line change
Expand Up @@ -3864,12 +3864,21 @@
(transient inferred) explicit))
explicit))

(defn- inheritance-info [t]
(let [t' (full-class-info t)
type-env (type-env-for (:element-name t) (:type-parameters t) (:type-parameters t'))
actual-types (fn [types] (map #(actual-type % type-env) types))]
(-> t'
(update :super actual-type type-env)
(update :mixins actual-types)
(update :interfaces actual-types))))

(defn- inheritance-graph [dart-type]
(loop [g {} todos [dart-type]]
(if-some [{cqnt :canon-qname :as t} (peek todos)]
(if (g cqnt)
(recur g (pop todos))
(let [{:keys [super mixins interfaces]} (full-class-info t)
(let [{:keys [super mixins interfaces]} (inheritance-info t)
ts (cond->> (concat mixins interfaces) super (cons super))]
(recur (assoc g cqnt {:type t :supers (into #{} (map :canon-qname) ts)})
(-> todos pop (into ts)))))
Expand All @@ -3889,14 +3898,14 @@
(or (@cache k)
(do
(vswap! cache assoc k dc-Object)
(let [ga (inheritance-graph (full-class-info a))
gb (inheritance-graph (full-class-info b))
(let [ga (inheritance-graph a)
gb (inheritance-graph b)
[cqn & too-many] (common-roots ga gb)
a (:type (ga cqn))
b (:type (gb cqn))
ca (:type (ga cqn))
cb (:type (gb cqn))
c (if too-many
dc-Object
(merge-type-params a b))]
dc-Object ; TODO union type
(merge-type-params ca cb))]
(vswap! cache assoc k c)
c)))))
(merge-type-params [a b]
Expand Down
9 changes: 9 additions & 0 deletions clj/test/cljd/test_clojure/core_test_cljd.cljd
Original file line number Diff line number Diff line change
Expand Up @@ -1073,3 +1073,12 @@
(deftest magicast-in-super-ctor
(is (= "helloWorld"
(str (SuperMagicastHello "World")))))

(deftest merging-types-preserve-type-parameters
(is (= :bar (let [{:strs [foo]} (Map.of {"foo" :bar})]
foo)))
(is (= :bar
(let [m (Map.of {"foo" :bar})
m (if (identity false) ^cljd.core/PersistentHashMap m m)
foo (-lookup m "foo")]
foo))))

0 comments on commit 0e1ef25

Please sign in to comment.