Welcome! Please see the About page for a little more info on how this works.

0 votes
in ClojureScript by
Whenever any deftype/defrecord defines methods on Object the CLJS compiler will emit an invalid type annotation which Closure complains about when running with type checking enabled.


(ns demo.type)

(deftype Foo [a b]
  Object
  (foo [this x]
    x))


produces this JS


/**
* @constructor
 * @implements {demo.type.Object}
*/
demo.type.Foo = (function (a,b){
this.a = a;
this.b = b;
});


produces the warning


Bad type annotation. Unknown type demo.type.Object


Looking at the analyzer data suggests that it indeed resolves incorrectly.


 ...
 :defs
 {Foo
  {:num-fields 2,
   :protocols #{demo.type/Object},
   :name demo.type/Foo,
   :file "demo/type.cljs",
   :end-column 13,
   :type true,
   :column 10,
   :line 3,
   :record false,
   :end-line 3,
   :skip-protocol-flag nil},


Not entirely sure how this bypasses checks but it might be a sign that there is an overly general check for Object which does not check the namespace.

AFAICT there are no bad effects on the CLJS analyzer/compiler. Closure does complain when type checking is enabled but otherwise seems unaffected.

Not yet sure where the issue starts, but looks like cljs.analyzer/resolve-var not correctly resolving Object without an ns, via [1].

[1] https://github.com/clojure/clojurescript/blob/998933f5090254611b46a2b86626fb17cabc994a/src/main/clojure/cljs/core.cljc#L1669-L1673

1 Answer

0 votes
by
Reference: https://clojure.atlassian.net/browse/CLJS-2380 (reported by thheller)
...