fix bug: invoke overload method disorder #104

Closed
uyong wants to merge 1 commits from uyong/fix-overload-method-bug into master
Showing only changes of commit 178462aab6 - Show all commits

View File

@@ -114,8 +114,19 @@ class JavaMethod extends JavaMember {
final JavaMethod[] methods;
// no parammeter method index in overload method
int noArgMethodIndex = -1;
Overload(JavaMethod[] methods) {
this.methods = methods;
JavaMethod m;
for (int i=0; i<methods.length; i++) {
m = methods[i];
if (m.fixedargs.length == 0 && m.varargs == null) {
noArgMethodIndex = i;
break;
}
}
}
public LuaValue call() {
@@ -140,6 +151,10 @@ class JavaMethod extends JavaMember {
private LuaValue invokeBestMethod(Object instance, Varargs args) {
JavaMethod best = null;
int n = args.narg();
if (n == 0 && noArgMethodIndex != -1) {
best = methods[noArgMethodIndex];
} else {
int score = CoerceLuaToJava.SCORE_UNCOERCIBLE;
for ( int i=0; i<methods.length; i++ ) {
int s = methods[i].score(args);
@@ -150,6 +165,7 @@ class JavaMethod extends JavaMember {
break;
}
}
}
// any match?
if ( best == null )