Bad "Cannot resolve..." In Call of Statically Imported Method
In a static method a call of a statically imported method is spuriously flagged as "Unable to resolve..."
Specifically, this code:
the call to canonicalName is shown in red with the tool-tip diagnostic "Cannot resolve symbol 'canonicalName'".
Changing the code to this (making the method non-static):
removes the error indication.
The code flagged as erroneous does compile (naturally) and execute as expected.
Randall Schulz
Please sign in to leave a comment.
It turns out that the missing type for the second argument was part of the problem. By supplying it, the error indication was eliminated:
Shows error:
No error indication:
RRS
Does canonicalName() have overloads?
Yes:
RRS
Could you file a JIRA request?
Is there actually a problem?
RRS
Randall Schulz wrote:
Surely. Resolver should correctly guess the target method based on
argument count and one matching argument.
Not exactly. The problem is actually in flagging the error in static context. It was a mistake, since Groovy does allow static methods to be injected using MOP. The request to make the resolve filter candidates that have the equal number of arguments as their parameters is really optimization that is not that easy to implement correctly: consider the case of varargs method (last parameter is of type List). And obviously it won't cover all the cases when we flag the error now though we shouldn't.
I've submitted a fix to 2.0, probably you want to port in to 1.5 as well.