Skip to content

Commit fe0c6e9

Browse files
SevereOverfl0wswannodette
authored andcommitted
CLJS-3284: Use of private deftype by public function in another namespace when inside an if causes warning
Suppress warnings in `type?` which are of private-var-access. A lot of type inference is automatic, and users don't necessarily know that it's happening. The type itself isn't secret in this context, even if the library indicates the user shouldn't rely on the exact existence of the type.
1 parent 5091bab commit fe0c6e9

File tree

4 files changed

+32
-1
lines changed

4 files changed

+32
-1
lines changed

src/main/clojure/cljs/analyzer.cljc

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1361,7 +1361,8 @@
13611361
[env t]
13621362
;; don't use resolve-existing-var to avoid warnings
13631363
(when (and (some? t) (symbol? t))
1364-
(let [var (resolve-var env t)]
1364+
(let [var (binding [*private-var-access-nowarn* true]
1365+
(resolve-var env t))]
13651366
(if-some [type (:type var)]
13661367
type
13671368
(if-some [type (-> var :info :type)]
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
(ns cljs-3284.bean)
2+
3+
(deftype ^:private SomeType [a])
4+
5+
(defn some-type
6+
[a]
7+
(SomeType. a))
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
(ns cljs-3284.core
2+
(:require
3+
cljs-3284.bean))
4+
5+
(defn maybe-bean
6+
[x]
7+
(if (object? x)
8+
(cljs-3284.bean/some-type x)
9+
x))

src/test/clojure/cljs/build_api_tests.clj

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -768,3 +768,17 @@
768768
(is (empty? @ws))))
769769
(.delete (io/file "package.json"))
770770
(test/delete-node-modules))
771+
772+
(deftest test-cljs-3284
773+
(testing "Type hint warnings don't fire just because of private types"
774+
(let [ws (atom [])
775+
out (.getPath (io/file (test/tmp-dir) "cljs-3235-out"))
776+
{:keys [inputs opts]} {:inputs (str (io/file "src" "test" "cljs_build"))
777+
:opts {:main 'cljs-3284.core
778+
:output-dir out
779+
:optimizations :none}}
780+
cenv (env/default-compiler-env opts)]
781+
(test/delete-out-files out)
782+
(ana/with-warning-handlers [(collecting-warning-handler ws)]
783+
(build/build (build/inputs (io/file inputs "cljs_3284/core.cljs")) opts cenv))
784+
(is (empty? @ws)))))

0 commit comments

Comments
 (0)