Skip to content
This repository has been archived by the owner on Jan 28, 2019. It is now read-only.

Commit

Permalink
Tweak when ^:dprecated var warnings are emitted
Browse files Browse the repository at this point in the history
This patch changes the behavior of var deprecation warnings to limit
false positives when loading deprecated namespaces. Specifically, when
compiling a deprecated namespace, uses of vars in the current namespace
or in any other deprecated namespace will not emit deprecation warnings.

This should hugely reduce warning noise, restricting deprecated warnings
to deprecated/non-deprecated contact points which is where they are
appropriate.
  • Loading branch information
arrdem committed Feb 1, 2016
1 parent 4a19992 commit b6c3ee8
Showing 1 changed file with 16 additions and 4 deletions.
20 changes: 16 additions & 4 deletions src/jvm/clojure/lang/Compiler.java
Original file line number Diff line number Diff line change
Expand Up @@ -378,6 +378,15 @@ static boolean isPedantic() {
return RT.booleanCast(getCompilerOption(pedanticKey));
}

static boolean isDeprecated(Var v) {
return (RT.booleanCast(RT.get(v.meta(), deprecatedKey, false))
|| isDeprecated(v.ns));
}

static boolean isDeprecated(Namespace n) {
return RT.booleanCast(RT.get(n.meta(), deprecatedKey, false));
}

static Symbol resolveSymbol(Symbol sym) {
//already qualified or classname?
if (sym.name.indexOf('.') > 0) {
Expand Down Expand Up @@ -6780,16 +6789,19 @@ private static Expr analyzeSymbol(Symbol sym) {

String loc = String.format(" (%s:%d:%d)", SOURCE.get(), lineDeref(), columnDeref());
Object meta = RT.meta(v);
Namespace nsc = (Namespace) RT.CURRENT_NS.get();

if ((RT.booleanCast(RT.get(meta, deprecatedKey, false))
|| (RT.booleanCast(RT.get(v.ns, deprecatedKey, false))
&& !Util.equiv(v.ns, RT.CURRENT_NS.get())))
if (isDeprecated(v)
// Mask out warnings when the whole ns is deprecated
// Also handles the case of both nss being deprecated
&& !isDeprecated(nsc)
// Mask out warnings when not pedantic
&& isPedantic()) {
RT.errPrintWriter().println("Warning: using deprecated var: " + v.toString() + loc);
}

if (RT.booleanCast(RT.get(meta, privateKey, false))
&& !Util.equals(RT.CURRENT_NS.get(), v.ns)
&& !Util.equals(nsc, v.ns)
&& isPedantic()) {
RT.errPrintWriter().println("Warning: using private var in other ns: " + v.toString() + loc);
}
Expand Down

0 comments on commit b6c3ee8

Please sign in to comment.