-
Notifications
You must be signed in to change notification settings - Fork 193
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Wrong code navigation with switch and def #405
Comments
The selection from multiple candidates is implemented here in SimpleTypeLookup. protected MethodNode findMethodDeclaration0(List<MethodNode> candidates, List<ClassNode> arguments) {
// remember first entry in case exact match not found
MethodNode closestMatch = candidates.get(0);
if (arguments == null) {
arguments = Collections.emptyList();
}
// prefer retrieving the method with the same number of args as specified in the parameter.
// if none exists, or parameter is -1, then arbitrarily choose the first.
for (Iterator<MethodNode> iterator = candidates.iterator(); iterator.hasNext();) {
MethodNode maybeMethod = iterator.next();
Parameter[] parameters = maybeMethod.getParameters();
if (parameters.length == 0 && arguments.isEmpty()) {
return maybeMethod.getOriginal();
}
if (parameters.length == arguments.size()) {
Boolean suitable = isTypeCompatible(arguments, parameters);
if (Boolean.TRUE.equals(suitable)) {
return maybeMethod.getOriginal();
}
if (!Boolean.FALSE.equals(suitable)) {
closestMatch = maybeMethod.getOriginal();
continue; // don't remove
}
}
iterator.remove();
}
return closestMatch;
} |
I can make a simple fix to handle your specific case. That is, overloads where the desired match has number of parameters matching arguments and all other overloads do not have matching number of parameters. This does not generalize to type inferencing for This will also not fix the ambiguous case of variadic methods. For example, if you had |
I see, but then (when multiple overloads have the same number of parameters, but of different types) probably also compilation with But, at least in this specific case, there's no ambiguity, at least for the Groovy compiler/runtime. |
Part of the issue is that the selection of Note: If |
I perfectly understand this is not a trivial case, thank you! |
Fix for issue #405: fallback to overload with matching parameter count
Ready to test in Eclipse Oxygen |
Verified in 3.0.0.xx-201801112223-e47, thank you! 👍 I see you're changing the name of this plugin to "Eclipse Groovy Development Tools", which sounds good to me. Why not then taking the opportunity to also change the packaging away from org.codehaus then? :-) |
Consider the following:
And:
Hit F3 over the call to
foo(String, Date, Date)
infoo(String, MyEnum)
and/or look at the hover: Greclipse thinks that call is forfoo(String, MyEnum)
itself.The cause of the problem seems to be
d1
andd2
be declared asdef
together with the presence of the switch.I think this case is a bit complicated to correctly analyse, but probably something can be done, because if you invoke Call Hierarchy (Ctrl+Alt+H) from
foo(String, Date, Date)
, the call fromfoo(String, MyEnum)
is correctly detected!The text was updated successfully, but these errors were encountered: