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

Commit

Permalink
Deprecated arity warnings for static invoke
Browse files Browse the repository at this point in the history
  • Loading branch information
arrdem committed Apr 13, 2016
1 parent f0cc732 commit dc39f39
Showing 1 changed file with 36 additions and 17 deletions.
53 changes: 36 additions & 17 deletions src/jvm/clojure/lang/Compiler.java
Original file line number Diff line number Diff line change
Expand Up @@ -3191,14 +3191,28 @@ private Type getReturnType() {
}

public static Expr parse(Var v, ISeq args, Object tag) {
if (!v.isBound() || v.get() == null || !(v.get() instanceof AFn)) {
if (!v.isBound() || v.get() == null || !(v.get() instanceof IFn)) {
return null;
}

ISeq arglists = (ISeq) RT.get(RT.meta(v), arglistsKey);
if (arglists == null) {
arglists = (ISeq) RT.get(RT.meta(v.get()), arglistsKey);
}

Class c = v.get().getClass();
String cname = c.getName();
java.lang.reflect.Method[] allmethods = c.getMethods();

IPersistentVector theargs = null;
if(arglists != null) {
for (Object o : RT.seq(arglists)) {
if (FnMethod.arglistMatches(RT.seq(o), args)) {
theargs = (IPersistentVector) o;
}
}
}

boolean variadic = false;
int argcount = RT.count(args);
java.lang.reflect.Method method = null;
Expand All @@ -3222,6 +3236,11 @@ public static Expr parse(Var v, ISeq args, Object tag) {
return null;
}

if (RT.booleanCast(RT.get(RT.meta(theargs), deprecatedKey))
&& warnOnDeprecated()) {
RT.errPrintWriter().println("Warning: invoking deprecated arity " + v + " " + theargs + " " + RT.getPos());
}

Class retClass = method.getReturnType();

Class[] paramClasses = method.getParameterTypes();
Expand Down Expand Up @@ -3466,14 +3485,12 @@ static public Expr parse(C context, ISeq form) {
Var v = ((VarExpr)fexpr).var;
Object meta = RT.meta(v);
Object arglists = RT.get(meta, arglistsKey);
int arity = RT.count(form.next());
IPersistentVector thelist = null;

if(arglists == null && v.isBound()) {
if (arglists == null && v.isBound()) {
arglists = RT.get(RT.meta(v.get()), arglistsKey);
}

if(arglists != null) {
IPersistentVector thelist = null;
if (arglists != null) {
for (Object o : RT.seq(arglists)) {
IPersistentVector args = (IPersistentVector) o;

Expand All @@ -3483,17 +3500,19 @@ static public Expr parse(C context, ISeq form) {
String primc = FnMethod.primInterface(args);
if (primc != null)
return analyze(context,
((IObj) RT.listStar(Symbol.intern(".invokePrim"),
((Symbol) form.first()).withMeta(RT.map(RT.TAG_KEY, Symbol.intern(primc))),
form.next())).withMeta((IPersistentMap) RT.conj(RT.meta(v), RT.meta(form))));
((IObj) RT.listStar(Symbol.intern(".invokePrim"),
((Symbol) form.first()).withMeta(RT.map(RT.TAG_KEY, Symbol.intern(primc))),
form.next())).withMeta((IPersistentMap) RT.conj(RT.meta(v), RT.meta(form))));

break;
}
}
}

if (thelist != null
&& RT.booleanCast(RT.get(RT.meta(thelist), deprecatedKey))
&& warnOnDeprecated()) {
RT.errPrintWriter().println("Warning: invoking deprecated arity " + thelist + " at" + RT.getPos());
if (thelist != null
&& RT.booleanCast(RT.get(RT.meta(thelist), deprecatedKey))
&& warnOnDeprecated()) {
RT.errPrintWriter().println("Warning: invoking deprecated arity " + v + " " + thelist + " " + RT.getPos());
}
}

Expand Down Expand Up @@ -4760,15 +4779,15 @@ static public String primInterface(IPersistentVector arglist) {

static public boolean arglistMatches(ISeq arglist, ISeq args) {
// RT.errPrintWriter().println(" Trying to match " + arglist + " to " + args);
while(true) {
while (true) {
Object binding = RT.first(arglist);
Object expr = RT.first(args);

if(Util.equals(binding, _AMP_)) {
if (Util.equals(binding, _AMP_)) {
return true;
} else if(args == null && arglist == null) {
} else if (args == null && arglist == null) {
return true;
} else if(binding != null && args != null) {
} else if (binding != null && args != null) {
arglist = RT.next(arglist);
args = RT.next(args);
continue;
Expand Down

0 comments on commit dc39f39

Please sign in to comment.