Skip to content

Commit 3915230

Browse files
author
jcompagne
committed
better matching for overloaded methods
1 parent fa80084 commit 3915230

File tree

1 file changed

+17
-3
lines changed

1 file changed

+17
-3
lines changed

plugins/org.eclipse.dltk.javascript.core/src/org/eclipse/dltk/internal/javascript/validation/JavaScriptValidations.java

Lines changed: 17 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,9 @@
3030
import org.eclipse.dltk.javascript.typeinfo.model.JSType;
3131
import org.eclipse.dltk.javascript.typeinfo.model.Member;
3232
import org.eclipse.dltk.javascript.typeinfo.model.Method;
33+
import org.eclipse.dltk.javascript.typeinfo.model.Parameter;
3334
import org.eclipse.dltk.javascript.typeinfo.model.Type;
35+
import org.eclipse.emf.common.util.EList;
3436

3537
public class JavaScriptValidations {
3638

@@ -146,15 +148,27 @@ public static Method selectMethod(List<Method> methods,
146148
if (argCountMatches == null) {
147149
argCountMatches = method;
148150
} else {
149-
argCountMatches = null;
150-
break;
151+
boolean match = false;
152+
EList<Parameter> parameters = method.getParameters();
153+
for (int i = 0; i < parameters.size(); i++) {
154+
JSType argumentType = typeOf(arguments[i]);
155+
JSType parameterType = parameters.get(i).getType();
156+
// todo should we have the context here to call
157+
// context.resolveTypeRef()?
158+
match = JSTypeSet.normalize(parameterType)
159+
.isAssignableFrom(
160+
JSTypeSet.normalize(argumentType));
161+
if (!match)
162+
break;
163+
}
164+
if (match)
165+
argCountMatches = method;
151166
}
152167
}
153168
}
154169
if (argCountMatches != null) {
155170
return argCountMatches;
156171
}
157-
// TODO implement additional checks
158172
return methods.get(0);
159173
}
160174

0 commit comments

Comments
 (0)