Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

compiler warns on deprecated function and protocol use

If a deprecated function is invoked or a deprected protocol is
implemented the compiler will issue a warning.

These warnings can be suppressed by binding *cljs-warn-fn-deprecated*
to false or by attaching the ^:deprecation-nowarn metadata to the
invocation form or to the protocol symbol.
  • Loading branch information...
commit 3ea593825f60c228f6a384be52bcf2fc4e417567 1 parent b0a397f
Brian netguy204 authored David Nolen committed
6 src/clj/cljs/analyzer.clj
View
@@ -50,6 +50,8 @@
(def ^:dynamic *cljs-warn-on-dynamic* true)
(def ^:dynamic *cljs-warn-on-fn-var* true)
(def ^:dynamic *cljs-warn-fn-arity* true)
+(def ^:dynamic *cljs-warn-fn-deprecated* true)
+(def ^:dynamic *cljs-warn-protocol-deprecated* true)
(def ^:dynamic *unchecked-if* (atom false))
(def ^:dynamic *cljs-static-fns* false)
(def ^:dynamic *cljs-macros-path* "/cljs/core")
@@ -839,6 +841,10 @@
(and variadic (< argc max-fixed-arity))))
(warning env
(str "WARNING: Wrong number of args (" argc ") passed to " name)))))
+ (if (and *cljs-warn-fn-deprecated* (-> fexpr :info :deprecated)
+ (not (-> form meta :deprecation-nowarn)))
+ (warning env
+ (str "WARNING: " (-> fexpr :info :name) " is deprecated.")))
{:env env :op :invoke :form form :f fexpr :args argexprs
:tag (or (-> fexpr :info :tag) (-> form meta :tag)) :children (into [fexpr] argexprs)})))
12 src/clj/cljs/core.clj
View
@@ -447,9 +447,15 @@
warn-if-not-protocol #(when-not (= 'Object %)
(if cljs.analyzer/*cljs-warn-on-undeclared*
(if-let [var (cljs.analyzer/resolve-existing-var (dissoc &env :locals) %)]
- (when-not (:protocol-symbol var)
- (cljs.analyzer/warning &env
- (core/str "WARNING: Symbol " % " is not a protocol")))
+ (do
+ (when-not (:protocol-symbol var)
+ (cljs.analyzer/warning &env
+ (core/str "WARNING: Symbol " % " is not a protocol")))
+ (when (and cljs.analyzer/*cljs-warn-protocol-deprecated*
+ (-> var :deprecated)
+ (not (-> % meta :deprecation-nowarn)))
+ (cljs.analyzer/warning &env
+ (core/str "WARNING: Protocol " % " is deprecated"))))
(cljs.analyzer/warning &env
(core/str "WARNING: Can't resolve protocol symbol " %)))))
skip-flag (set (-> tsym meta :skip-protocol-flag))]
128 src/cljs/cljs/core.cljs
View
@@ -388,7 +388,7 @@
ICollection
(-conj [_ o] (list o))
- IPrintable
+ ^:deprecation-nowarn IPrintable
(-pr-seq [o] (list "nil"))
IPrintWithWriter
@@ -6348,7 +6348,7 @@ reduces them without incurring seq initialization"
[fmt & args]
(print (apply format fmt args)))
-(extend-protocol IPrintable
+(extend-protocol ^:deprecation-nowarn IPrintable
boolean
(-pr-seq [bool opts] (list (str bool)))
@@ -6357,7 +6357,7 @@ reduces them without incurring seq initialization"
array
(-pr-seq [a opts]
- (pr-sequential pr-seq "#<Array [" ", " "]>" opts a))
+ ^:deprecation-nowarn (pr-sequential pr-seq "#<Array [" ", " "]>" opts a))
string
(-pr-seq [obj opts]
@@ -6398,89 +6398,89 @@ reduces them without incurring seq initialization"
"00:00\""))))
LazySeq
- (-pr-seq [coll opts] (pr-sequential pr-seq "(" " " ")" opts coll))
+ (-pr-seq [coll opts] ^:deprecation-nowarn (pr-sequential pr-seq "(" " " ")" opts coll))
IndexedSeq
- (-pr-seq [coll opts] (pr-sequential pr-seq "(" " " ")" opts coll))
+ (-pr-seq [coll opts] ^:deprecation-nowarn (pr-sequential pr-seq "(" " " ")" opts coll))
RSeq
- (-pr-seq [coll opts] (pr-sequential pr-seq "(" " " ")" opts coll))
+ (-pr-seq [coll opts] ^:deprecation-nowarn (pr-sequential pr-seq "(" " " ")" opts coll))
PersistentQueue
- (-pr-seq [coll opts] (pr-sequential pr-seq "#queue [" " " "]" opts (seq coll)))
+ (-pr-seq [coll opts] ^:deprecation-nowarn (pr-sequential pr-seq "#queue [" " " "]" opts (seq coll)))
PersistentTreeMapSeq
- (-pr-seq [coll opts] (pr-sequential pr-seq "(" " " ")" opts coll))
+ (-pr-seq [coll opts] ^:deprecation-nowarn (pr-sequential pr-seq "(" " " ")" opts coll))
NodeSeq
- (-pr-seq [coll opts] (pr-sequential pr-seq "(" " " ")" opts coll))
+ (-pr-seq [coll opts] ^:deprecation-nowarn (pr-sequential pr-seq "(" " " ")" opts coll))
ArrayNodeSeq
- (-pr-seq [coll opts] (pr-sequential pr-seq "(" " " ")" opts coll))
+ (-pr-seq [coll opts] ^:deprecation-nowarn (pr-sequential pr-seq "(" " " ")" opts coll))
List
- (-pr-seq [coll opts] (pr-sequential pr-seq "(" " " ")" opts coll))
+ (-pr-seq [coll opts] ^:deprecation-nowarn (pr-sequential pr-seq "(" " " ")" opts coll))
Cons
- (-pr-seq [coll opts] (pr-sequential pr-seq "(" " " ")" opts coll))
+ (-pr-seq [coll opts] ^:deprecation-nowarn (pr-sequential pr-seq "(" " " ")" opts coll))
EmptyList
(-pr-seq [coll opts] (list "()"))
Vector
- (-pr-seq [coll opts] (pr-sequential pr-seq "[" " " "]" opts coll))
+ (-pr-seq [coll opts] ^:deprecation-nowarn (pr-sequential pr-seq "[" " " "]" opts coll))
PersistentVector
- (-pr-seq [coll opts] (pr-sequential pr-seq "[" " " "]" opts coll))
+ (-pr-seq [coll opts] ^:deprecation-nowarn (pr-sequential pr-seq "[" " " "]" opts coll))
ChunkedCons
- (-pr-seq [coll opts] (pr-sequential pr-seq "(" " " ")" opts coll))
+ (-pr-seq [coll opts] ^:deprecation-nowarn (pr-sequential pr-seq "(" " " ")" opts coll))
ChunkedSeq
- (-pr-seq [coll opts] (pr-sequential pr-seq "(" " " ")" opts coll))
+ (-pr-seq [coll opts] ^:deprecation-nowarn (pr-sequential pr-seq "(" " " ")" opts coll))
Subvec
- (-pr-seq [coll opts] (pr-sequential pr-seq "[" " " "]" opts coll))
+ (-pr-seq [coll opts] ^:deprecation-nowarn (pr-sequential pr-seq "[" " " "]" opts coll))
BlackNode
- (-pr-seq [coll opts] (pr-sequential pr-seq "[" " " "]" opts coll))
+ (-pr-seq [coll opts] ^:deprecation-nowarn (pr-sequential pr-seq "[" " " "]" opts coll))
RedNode
- (-pr-seq [coll opts] (pr-sequential pr-seq "[" " " "]" opts coll))
+ (-pr-seq [coll opts] ^:deprecation-nowarn (pr-sequential pr-seq "[" " " "]" opts coll))
ObjMap
(-pr-seq [coll opts]
- (let [pr-pair (fn [keyval] (pr-sequential pr-seq "" " " "" opts keyval))]
- (pr-sequential pr-pair "{" ", " "}" opts coll)))
+ (let [pr-pair (fn [keyval] ^:deprecation-nowarn (pr-sequential pr-seq "" " " "" opts keyval))]
+ ^:deprecation-nowarn (pr-sequential pr-pair "{" ", " "}" opts coll)))
HashMap
(-pr-seq [coll opts]
- (let [pr-pair (fn [keyval] (pr-sequential pr-seq "" " " "" opts keyval))]
- (pr-sequential pr-pair "{" ", " "}" opts coll)))
+ (let [pr-pair (fn [keyval] ^:deprecation-nowarn (pr-sequential pr-seq "" " " "" opts keyval))]
+ ^:deprecation-nowarn (pr-sequential pr-pair "{" ", " "}" opts coll)))
PersistentArrayMap
(-pr-seq [coll opts]
- (let [pr-pair (fn [keyval] (pr-sequential pr-seq "" " " "" opts keyval))]
- (pr-sequential pr-pair "{" ", " "}" opts coll)))
+ (let [pr-pair (fn [keyval] ^:deprecation-nowarn (pr-sequential pr-seq "" " " "" opts keyval))]
+ ^:deprecation-nowarn (pr-sequential pr-pair "{" ", " "}" opts coll)))
PersistentHashMap
(-pr-seq [coll opts]
- (let [pr-pair (fn [keyval] (pr-sequential pr-seq "" " " "" opts keyval))]
- (pr-sequential pr-pair "{" ", " "}" opts coll)))
+ (let [pr-pair (fn [keyval] ^:deprecation-nowarn (pr-sequential pr-seq "" " " "" opts keyval))]
+ ^:deprecation-nowarn (pr-sequential pr-pair "{" ", " "}" opts coll)))
PersistentTreeMap
(-pr-seq [coll opts]
- (let [pr-pair (fn [keyval] (pr-sequential pr-seq "" " " "" opts keyval))]
- (pr-sequential pr-pair "{" ", " "}" opts coll)))
+ (let [pr-pair (fn [keyval] ^:deprecation-nowarn (pr-sequential pr-seq "" " " "" opts keyval))]
+ ^:deprecation-nowarn (pr-sequential pr-pair "{" ", " "}" opts coll)))
PersistentHashSet
- (-pr-seq [coll opts] (pr-sequential pr-seq "#{" " " "}" opts coll))
+ (-pr-seq [coll opts] ^:deprecation-nowarn (pr-sequential pr-seq "#{" " " "}" opts coll))
PersistentTreeSet
- (-pr-seq [coll opts] (pr-sequential pr-seq "#{" " " "}" opts coll))
+ (-pr-seq [coll opts] ^:deprecation-nowarn (pr-sequential pr-seq "#{" " " "}" opts coll))
Range
- (-pr-seq [coll opts] (pr-sequential pr-seq "(" " " ")" opts coll)))
+ (-pr-seq [coll opts] ^:deprecation-nowarn (pr-sequential pr-seq "(" " " ")" opts coll)))
(extend-protocol IPrintWithWriter
boolean
@@ -6491,7 +6491,7 @@ reduces them without incurring seq initialization"
array
(-pr-writer [a writer opts]
- (pr-sequential-writer writer pr-writer "#<Array [" ", " "]>" opts a))
+ ^:deprecation-nowarn (pr-sequential-writer writer pr-writer "#<Array [" ", " "]>" opts a))
string
(-pr-writer [obj writer opts]
@@ -6534,89 +6534,89 @@ reduces them without incurring seq initialization"
"00:00\"")))
LazySeq
- (-pr-writer [coll writer opts] (pr-sequential-writer writer pr-writer "(" " " ")" opts coll))
+ (-pr-writer [coll writer opts] ^:deprecation-nowarn (pr-sequential-writer writer pr-writer "(" " " ")" opts coll))
IndexedSeq
- (-pr-writer [coll writer opts] (pr-sequential-writer writer pr-writer "(" " " ")" opts coll))
+ (-pr-writer [coll writer opts] ^:deprecation-nowarn (pr-sequential-writer writer pr-writer "(" " " ")" opts coll))
RSeq
- (-pr-writer [coll writer opts] (pr-sequential-writer writer pr-writer "(" " " ")" opts coll))
+ (-pr-writer [coll writer opts] ^:deprecation-nowarn (pr-sequential-writer writer pr-writer "(" " " ")" opts coll))
PersistentQueue
- (-pr-writer [coll writer opts] (pr-sequential-writer writer pr-writer "#queue [" " " "]" opts (seq coll)))
+ (-pr-writer [coll writer opts] ^:deprecation-nowarn (pr-sequential-writer writer pr-writer "#queue [" " " "]" opts (seq coll)))
PersistentTreeMapSeq
- (-pr-writer [coll writer opts] (pr-sequential-writer writer pr-writer "(" " " ")" opts coll))
+ (-pr-writer [coll writer opts] ^:deprecation-nowarn (pr-sequential-writer writer pr-writer "(" " " ")" opts coll))
NodeSeq
- (-pr-writer [coll writer opts] (pr-sequential-writer writer pr-writer "(" " " ")" opts coll))
+ (-pr-writer [coll writer opts] ^:deprecation-nowarn (pr-sequential-writer writer pr-writer "(" " " ")" opts coll))
ArrayNodeSeq
- (-pr-writer [coll writer opts] (pr-sequential-writer writer pr-writer "(" " " ")" opts coll))
+ (-pr-writer [coll writer opts] ^:deprecation-nowarn (pr-sequential-writer writer pr-writer "(" " " ")" opts coll))
List
- (-pr-writer [coll writer opts] (pr-sequential-writer writer pr-writer "(" " " ")" opts coll))
+ (-pr-writer [coll writer opts] ^:deprecation-nowarn (pr-sequential-writer writer pr-writer "(" " " ")" opts coll))
Cons
- (-pr-writer [coll writer opts] (pr-sequential-writer writer pr-writer "(" " " ")" opts coll))
+ (-pr-writer [coll writer opts] ^:deprecation-nowarn (pr-sequential-writer writer pr-writer "(" " " ")" opts coll))
EmptyList
(-pr-writer [coll writer opts] (-write writer "()"))
Vector
- (-pr-writer [coll writer opts] (pr-sequential-writer writer pr-writer "[" " " "]" opts coll))
+ (-pr-writer [coll writer opts] ^:deprecation-nowarn (pr-sequential-writer writer pr-writer "[" " " "]" opts coll))
PersistentVector
- (-pr-writer [coll writer opts] (pr-sequential-writer writer pr-writer "[" " " "]" opts coll))
+ (-pr-writer [coll writer opts] ^:deprecation-nowarn (pr-sequential-writer writer pr-writer "[" " " "]" opts coll))
ChunkedCons
- (-pr-writer [coll writer opts] (pr-sequential-writer writer pr-writer "(" " " ")" opts coll))
+ (-pr-writer [coll writer opts] ^:deprecation-nowarn (pr-sequential-writer writer pr-writer "(" " " ")" opts coll))
ChunkedSeq
- (-pr-writer [coll writer opts] (pr-sequential-writer writer pr-writer "(" " " ")" opts coll))
+ (-pr-writer [coll writer opts] ^:deprecation-nowarn (pr-sequential-writer writer pr-writer "(" " " ")" opts coll))
Subvec
- (-pr-writer [coll writer opts] (pr-sequential-writer writer pr-writer "[" " " "]" opts coll))
+ (-pr-writer [coll writer opts] ^:deprecation-nowarn (pr-sequential-writer writer pr-writer "[" " " "]" opts coll))
BlackNode
- (-pr-writer [coll writer opts] (pr-sequential-writer writer pr-writer "[" " " "]" opts coll))
+ (-pr-writer [coll writer opts] ^:deprecation-nowarn (pr-sequential-writer writer pr-writer "[" " " "]" opts coll))
RedNode
- (-pr-writer [coll writer opts] (pr-sequential-writer writer pr-writer "[" " " "]" opts coll))
+ (-pr-writer [coll writer opts] ^:deprecation-nowarn (pr-sequential-writer writer pr-writer "[" " " "]" opts coll))
ObjMap
(-pr-writer [coll writer opts]
- (let [pr-pair (fn [keyval] (pr-sequential-writer writer pr-writer "" " " "" opts keyval))]
- (pr-sequential-writer writer pr-pair "{" ", " "}" opts coll)))
+ (let [pr-pair (fn [keyval] ^:deprecation-nowarn (pr-sequential-writer writer pr-writer "" " " "" opts keyval))]
+ ^:deprecation-nowarn (pr-sequential-writer writer pr-pair "{" ", " "}" opts coll)))
HashMap
(-pr-writer [coll writer opts]
- (let [pr-pair (fn [keyval] (pr-sequential-writer writer pr-writer "" " " "" opts keyval))]
- (pr-sequential-writer writer pr-pair "{" ", " "}" opts coll)))
+ (let [pr-pair (fn [keyval] ^:deprecation-nowarn (pr-sequential-writer writer pr-writer "" " " "" opts keyval))]
+ ^:deprecation-nowarn (pr-sequential-writer writer pr-pair "{" ", " "}" opts coll)))
PersistentArrayMap
(-pr-writer [coll writer opts]
- (let [pr-pair (fn [keyval] (pr-sequential-writer writer pr-writer "" " " "" opts keyval))]
- (pr-sequential-writer writer pr-pair "{" ", " "}" opts coll)))
+ (let [pr-pair (fn [keyval] ^:deprecation-nowarn (pr-sequential-writer writer pr-writer "" " " "" opts keyval))]
+ ^:deprecation-nowarn (pr-sequential-writer writer pr-pair "{" ", " "}" opts coll)))
PersistentHashMap
(-pr-writer [coll writer opts]
- (let [pr-pair (fn [keyval] (pr-sequential-writer writer pr-writer "" " " "" opts keyval))]
- (pr-sequential-writer writer pr-pair "{" ", " "}" opts coll)))
+ (let [pr-pair (fn [keyval] ^:deprecation-nowarn (pr-sequential-writer writer pr-writer "" " " "" opts keyval))]
+ ^:deprecation-nowarn (pr-sequential-writer writer pr-pair "{" ", " "}" opts coll)))
PersistentTreeMap
(-pr-writer [coll writer opts]
- (let [pr-pair (fn [keyval] (pr-sequential-writer writer pr-writer "" " " "" opts keyval))]
- (pr-sequential-writer writer pr-pair "{" ", " "}" opts coll)))
+ (let [pr-pair (fn [keyval] ^:deprecation-nowarn (pr-sequential-writer writer pr-writer "" " " "" opts keyval))]
+ ^:deprecation-nowarn (pr-sequential-writer writer pr-pair "{" ", " "}" opts coll)))
PersistentHashSet
- (-pr-writer [coll writer opts] (pr-sequential-writer writer pr-writer "#{" " " "}" opts coll))
+ (-pr-writer [coll writer opts] ^:deprecation-nowarn (pr-sequential-writer writer pr-writer "#{" " " "}" opts coll))
PersistentTreeSet
- (-pr-writer [coll writer opts] (pr-sequential-writer writer pr-writer "#{" " " "}" opts coll))
+ (-pr-writer [coll writer opts] ^:deprecation-nowarn (pr-sequential-writer writer pr-writer "#{" " " "}" opts coll))
Range
- (-pr-writer [coll writer opts] (pr-sequential-writer writer pr-writer "(" " " ")" opts coll)))
+ (-pr-writer [coll writer opts] ^:deprecation-nowarn (pr-sequential-writer writer pr-writer "(" " " ")" opts coll)))
;; IComparable
@@ -6636,7 +6636,7 @@ reduces them without incurring seq initialization"
IMeta
(-meta [_] meta)
- IPrintable
+ ^:deprecation-nowarn IPrintable
(-pr-seq [a opts]
(concat ["#<Atom: "] (-pr-seq state opts) ">"))
@@ -7181,7 +7181,7 @@ reduces them without incurring seq initialization"
(-equiv [_ other]
(and (instance? UUID other) (identical? uuid (.-uuid other))))
- IPrintable
+ ^:deprecation-nowarn IPrintable
(-pr-seq [_ _]
(list (str "#uuid \"" uuid "\"")))
Please sign in to comment.
Something went wrong with that request. Please try again.