Permalink
Browse files

CLJS-687: error/warning when deftype/record constructor used as a

function
  • Loading branch information...
1 parent 8c6dd24 commit 792b2b87c9982a76093fcc3278dd246e8672627b @swannodette swannodette committed Nov 19, 2013
Showing with 12 additions and 4 deletions.
  1. +12 −4 src/clj/cljs/analyzer.clj
@@ -43,7 +43,8 @@
:multiple-variadic-overloads true
:variadic-max-arity true
:overload-arity true
- :extending-base-js-type true})
+ :extending-base-js-type true
+ :invoke-ctor true})
(declare message namespaces)
@@ -114,6 +115,10 @@
(str "Extending an existing JavaScript type - use a different symbol name "
"instead of " (:current-symbol info) " e.g " (:suggested-symbol info)))
+(defmethod error-message :invoke-ctor
+ [warning-type info]
+ (str "Cannot invoke type constructor " (-> info :fexpr :info :name) " as function "))
+
(defn ^:private default-warning-handler [warning-type env extra]
(when (warning-type *cljs-warnings*)
(when-let [s (error-message warning-type extra)]
@@ -1086,16 +1091,19 @@
fexpr (analyze enve f)
argexprs (vec (map #(analyze enve %) args))
argc (count args)]
- (if (and (:fn-arity *cljs-warnings*) (-> fexpr :info :fn-var))
+ (when (and (:fn-arity *cljs-warnings*) (-> fexpr :info :fn-var))
(let [{:keys [variadic max-fixed-arity method-params name]} (:info fexpr)]
(when (and (not (some #{argc} (map count method-params)))
(or (not variadic)
(and variadic (< argc max-fixed-arity))))
(warning :fn-arity env {:name name
:argc argc}))))
- (if (and (:fn-deprecated *cljs-warnings*) (-> fexpr :info :deprecated)
- (not (-> form meta :deprecation-nowarn)))
+ (when (and (:fn-deprecated *cljs-warnings*) (-> fexpr :info :deprecated)
+ (not (-> form meta :deprecation-nowarn)))
(warning :fn-deprecated env {:fexpr fexpr}))
+ (when (and (:invoke-ctor *cljs-warnings*)
+ (-> fexpr :info :type))
+ (warning :invoke-ctor env {:fexpr fexpr}))
{:env env :op :invoke :form form :f fexpr :args argexprs
:tag (or (-> fexpr :info :tag) (-> form meta :tag)) :children (into [fexpr] argexprs)})))

0 comments on commit 792b2b8

Please sign in to comment.