Skip to content

Commit 1c4eefa

Browse files
committed
CLJS-2767: Externs inference warnings for defrecord and deftype
Ignore constructor property access. Type hint `other` when we know the constructor is the same in defrecord -equiv implement. Add tests.
1 parent 00b8dea commit 1c4eefa

File tree

3 files changed

+21
-2
lines changed

3 files changed

+21
-2
lines changed

src/main/clojure/cljs/analyzer.cljc

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2928,7 +2928,8 @@
29282928
(vary-meta (normalize-js-tag target-tag)
29292929
update-in [:prefix] (fnil conj '[Object]) prop))
29302930
nil)]
2931-
(when (not (string/starts-with? (str prop) "cljs$"))
2931+
(when (and (not= 'constructor prop)
2932+
(not (string/starts-with? (str prop) "cljs$")))
29322933
;; Adding to Object
29332934
(when (= 'Object (first (-> tag meta :prefix)))
29342935
(warning :infer-warning env

src/main/clojure/cljs/core.cljc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1819,7 +1819,7 @@
18191819
(.. ~other ~(to-property field))))
18201820
base-fields)
18211821
(= (.-__extmap ~this)
1822-
(.-__extmap ~other)))))
1822+
(.-__extmap ~(with-meta other {:tag tagname}))))))
18231823
'IMeta
18241824
`(~'-meta [this#] ~'__meta)
18251825
'IWithMeta

src/test/clojure/cljs/analyzer_tests.clj

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1076,3 +1076,21 @@
10761076
:warnings ws
10771077
:warn false})]
10781078
(is (= (unsplit-lines ["Object.Component;"]) res))))
1079+
1080+
(deftest test-cljs-2767-deftype-defrecord
1081+
(let [ws (atom [])
1082+
res (infer-test-helper
1083+
{:forms '[(ns cjls-2767.core)
1084+
(defrecord Foo [])]
1085+
:externs ["src/test/externs/test.js"]
1086+
:warnings ws
1087+
:with-core? true})]
1088+
(is (empty? @ws)))
1089+
(let [ws (atom [])
1090+
res (infer-test-helper
1091+
{:forms '[(ns cjls-2767.core)
1092+
(deftype Foo [])]
1093+
:externs ["src/test/externs/test.js"]
1094+
:warnings ws
1095+
:with-core? true})]
1096+
(is (empty? @ws))))

0 commit comments

Comments
 (0)