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

+5 votes
in Errors by
From the mailing list http://groups.google.com/group/clojure/msg/c41d909bd58e4534. It is easy to use deprecated namespaces or vars without knowing you are doing so. The documentation warnings are small, and there is no compiler warning.

*Proposed:*

* Add new {{\*warn-on-deprecated*}} dynamic var, defaulted to false
* Warn to stderr when {{{:deprecated true}}} namespace is loaded.
* Warn to stderr when {{{:deprecated true}}} var is analyzed.
* Warn to stderr when {{{:deprecated true}}} macro is expanded.
* New system property clojure.compiler.warn-on-deprecated
* Compile Clojure itself with clojure.compiler.warn-on-deprecated
* Fix deprecation warnings inside Clojure (replicate, clear-agent-errors)
* Mark clojure.parallel as deprecated with :deprecation tag

Examples:


(set! *warn-on-deprecated* true)

;; use of a deprecated var (on compile)
(defn ^:deprecated f [x] x)
(f 5)
;;=> Deprecation warning, NO_SOURCE_PATH:7:1 : var #'user/f is deprecated

;; use of a deprecated macro (on macro expansion)
(defmacro ^:deprecated m [x] x)
(m 5)
;;=> Deprecation warning, NO_SOURCE_PATH:7:1 : macro #'user/m is deprecated

;; use of a deprecated namespace (on load)
(ns foo {:deprecated "1.1"})
(ns bar (:require foo))
;;=> Deprecation warning: loading deprecated namespace `foo` from namespace `bar`


*Patch:* 706-deprecated-ns-var-warnings-tested-3.diff

*Questions:* Should default for deprecation warnings be true instead? People upgrading are likely to see new warnings which might be surprising.

* Should default be to warn or not warn on deprecated?

25 Answers

0 votes
by

Comment made by: alexmiller

There is a middle ground here to turn it off by default in the compiler, but to turn it on by default in the tools (like lein). But there's a reasonable chance that whatever I prefer, Rich will have a preference that overrules it when it gets to him. :)

I think creating more complexity around namespace prefixes is unlikely to help this ticket move forward.

0 votes
by

Comment made by: cezarykosko

Uploaded a patch that coalesces var/ns-related patches by Luke & adds tests.
The patch does not, however, warn the user about deprecated macros, I assume I should adjust it, then?

Also, I'm not able adjust the description, so how do I take care of Alex's list's first bullet?

0 votes
by

Comment made by: jafingerhut

Cezary, I have bumped up your permissions on JIRA so you should be able to edit tickets now. Please reload the page and try again.

0 votes
by
_Comment made by: alexmiller_

* The {{if}} in the first change in core.clj should be a {{when}} instead.
* Can namespace deprecation warning include more about where this is occurring?
* I'm having a hard time reproducing the deprecated ns warning in a manual test (see below). There seems to be something weird about the binding+printf as the conditions appear to be satisfied. I'm thinking it has something to do with flushing {{\*err*}}? Seems like {{(println "Warning: loading deprecated ns" lib)}} would be better there.


(set! *warn-on-deprecated* true)
(ns foo {:deprecated true})
(ns bar (:require foo))


* src/jvm/clojure/lang/Compile.java needs added support for clojure.compile.warn-on-deprecated RT flag
* I think we should turn on warn-on-deprecated in the Clojure build itself (in build.xml)
* If you do that, the following deprecation warnings exist in the Clojure build itself and we should fix those:

     [java] Deprecation warning, clojure/core_proxy.clj:112:75 : var #'clojure.core/replicate is tagged as deprecated
     [java] Deprecation warning, clojure/genclass.clj:149:41 : var #'clojure.core/replicate is tagged as deprecated
     [java] Deprecation warning, clojure/genclass.clj:235:65 : var #'clojure.core/replicate is tagged as deprecated
     [java] Deprecation warning, clojure/test/junit.clj:118:22 : var #'clojure.test/file-position is tagged as deprecated

* Mark clojure.parallel as deprecated in the ns meta
0 votes
by

Comment made by: cezarykosko

Uploaded a new diff addressing the comments & added warning on macroexpansion.

As far as the namespace deprecation warning goes, though, the code's only printing the current namespace, did not know whether there was a decent way to get a file/line combo.

0 votes
by

Comment made by: alexmiller

One more (hopefully final) round and then I think we're good:

  • The docstring for warn-on-deprecated should be updated now that we've expanded scope to cover ns too.
  • In the deprecated ns warning message, can we make it: "Deprecation warning: loading deprecated namespace foo from namespace bar."
  • In the macro and var warnings can we change "is tagged as deprecated" to just "is deprecated"?
  • Clean up the hanging parens in test/clojure/test_clojure/compilation/deprecated.clj

Thanks for the work on this!!

0 votes
by

Comment made by: alexmiller

Marking pre-screened for Rich to look at.

0 votes
by

Comment made by: simongray

What happened to this feature? Is it still coming?

0 votes
by
0 votes
by

Would be great to see this in the next clojure version.

by
Hey Eugen, we now have tools like clj-kondo, that warn us about the usage of deprecated functions/vars.


Locally/devtime, you can use clojure-lsp (that uses clj-kondo) to warn you at IDE-level

At CI, you can use clojure-lsp command line API, or kondo as a codelinter.


I see no reason to add this to the compiler.

https://github.com/clj-kondo/clj-kondo/blob/43f8c0613150e047c73a79ee8adb9f3cc46476de/analysis/README.md#data
...