Skip to content

Commit

Permalink
CLJS-2767: Externs inference warnings for defrecord and deftype
Browse files Browse the repository at this point in the history
Ignore constructor property access. Type hint `other` when we know the
constructor is the same in defrecord -equiv implement.

Add tests.
  • Loading branch information
swannodette committed Jun 13, 2018
1 parent 00b8dea commit 1c4eefa
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 2 deletions.
3 changes: 2 additions & 1 deletion src/main/clojure/cljs/analyzer.cljc
Original file line number Diff line number Diff line change
Expand Up @@ -2928,7 +2928,8 @@
(vary-meta (normalize-js-tag target-tag)
update-in [:prefix] (fnil conj '[Object]) prop))
nil)]
(when (not (string/starts-with? (str prop) "cljs$"))
(when (and (not= 'constructor prop)
(not (string/starts-with? (str prop) "cljs$")))
;; Adding to Object
(when (= 'Object (first (-> tag meta :prefix)))
(warning :infer-warning env
Expand Down
2 changes: 1 addition & 1 deletion src/main/clojure/cljs/core.cljc
Original file line number Diff line number Diff line change
Expand Up @@ -1819,7 +1819,7 @@
(.. ~other ~(to-property field))))
base-fields)
(= (.-__extmap ~this)
(.-__extmap ~other)))))
(.-__extmap ~(with-meta other {:tag tagname}))))))
'IMeta
`(~'-meta [this#] ~'__meta)
'IWithMeta
Expand Down
18 changes: 18 additions & 0 deletions src/test/clojure/cljs/analyzer_tests.clj
Original file line number Diff line number Diff line change
Expand Up @@ -1076,3 +1076,21 @@
:warnings ws
:warn false})]
(is (= (unsplit-lines ["Object.Component;"]) res))))

(deftest test-cljs-2767-deftype-defrecord
(let [ws (atom [])
res (infer-test-helper
{:forms '[(ns cjls-2767.core)
(defrecord Foo [])]
:externs ["src/test/externs/test.js"]
:warnings ws
:with-core? true})]
(is (empty? @ws)))
(let [ws (atom [])
res (infer-test-helper
{:forms '[(ns cjls-2767.core)
(deftype Foo [])]
:externs ["src/test/externs/test.js"]
:warnings ws
:with-core? true})]
(is (empty? @ws))))

0 comments on commit 1c4eefa

Please sign in to comment.