Skip to content

Commit

Permalink
manually filter out matching callables with non-matching arguments le…
Browse files Browse the repository at this point in the history
…ngth

... this is necessary as the find logic matches argument by argument possibly leaving matches with arity > args.length

fixes #2923

p.s. possibly we still do not handle var-args well
kares committed Aug 14, 2015
1 parent a35930a commit bb98593
Showing 1 changed file with 14 additions and 1 deletion.
15 changes: 14 additions & 1 deletion core/src/main/java/org/jruby/java/dispatch/CallableSelector.java
Original file line number Diff line number Diff line change
@@ -185,6 +185,7 @@ private static <T extends ParameterTypes> T findMatchingCallableForArgs(final Ru
final T candidate = candidates.get(c);
final Class<?>[] cTypes = candidate.getParameterTypes();

// TODO still need to handle var-args better Class<?> lastType;
for ( int i = 0; i < msTypes.length; i++ ) {
final Class<?> msType = msTypes[i], cType = cTypes[i];
if ( msType != cType && msType.isAssignableFrom(cType) ) {
@@ -375,7 +376,19 @@ private static <T extends ParameterTypes> List<T> findCallableCandidates(final T
incoming = retained.toArray( new ParameterTypes[retained.size()] );
}

return retained;
// final step rule out argument length mismatch :
int j = 0; for ( int i = 0; i < retained.size(); i++ ) {
T callable = retained.get(i);
if ( callable.isVarArgs() ) {
if ( callable.getArity() > args.length - 1 ) continue;
}
else {
if ( callable.getArity() != args.length ) continue;
}
retained.set(j++, callable);
}

return j < retained.size() ? retained.subList(0, j) : retained;
}

private static int calcExactnessScore(final ParameterTypes callable, final IRubyObject[] args) {

0 comments on commit bb98593

Please sign in to comment.