-
Notifications
You must be signed in to change notification settings - Fork 194
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
Compiler error on code that compiles with groovyc #863
Comments
The reason for GROOVY-9058 is this check near the end of boolean lastArg = i == length - 1;
if (lastArg && inferredType.isArray()) {
if (inferredType.getComponentType().equals(originType)) {
inferredType = originType;
}
} STC has determined that the type of the closure parameter is |
I'm trying to isolate why the editor is having one behavior for this and the builder is getting another result. Also, you may want to give some feedback on GROOVY-9058. From the looks of the code in Groovy core, STC ignores the declared type of variable declarations in a lot of cases. I'm not sure what the overall reasoning is for this, but we need to prompt some kind of explanation/response to help guide what kind of changes fit that design. |
What about asking on the Groovy dev mailing list? Probably you can do it better than I could, otherwise let me know and I will ask there to take a look at GROOVY-9058... |
I added notes to GROOVY-9058 indicating that the very first comment contains the one and only suggested change to fix closure param inferencing under STC. I also created GROOVY-9064 for the case you describe here. I have tried some different possibilities and think I have a small change that will address this issue. You can lobby Groovy core to test and merge the changes if you wish. I will do some additional testing and commit the changes here if all goes well. |
Ready to test |
Hi Eric,
|
I made fixes in Groovy 2.5 and 3 -- I assumed you were using Groovy 2.5 from the bug metadata. The change was a little risky to patch Groovy 2.4 IMO. The outcome should be no compiler error for the case indicated here as well as in GROOVY-9058. In general, under static type checking (STC) if you declare the type of a variable explicitly, that is what gets used as the inferred type. If you use |
Ok, when I set Groovy 2.5 compiler and switch to Groovy 2.5 libraries for my project, it now works as groovyc. But the problem is still there when I use Groovy 2.4 (whose groovyc behaves correctly instead). |
I can try for a minimal fix for Groovy 2.4. I had mixed results with the compiler vs the editor without the additional changes. |
So I went back to your example verbatim and discovered why Groovyc and Greclipse have a different result. The return type of the method bar() is seen as if (lType.isUsingGenerics() && missesGenericsTypes(resultType) && isAssignment(op)) {
// unchecked assignment
// examples:
// List<A> list = []
// List<A> list = new LinkedList()
// Iterable<A> list = new LinkedList()
// in that case, the inferred type of the binary expression is the type of the RHS
// "completed" with generics type information available in the LHS
ClassNode completedType = GenericsUtils.parameterizeType(lType, resultType.getPlainNodeReference());
resultType = completedType;
} |
Ready to re-test |
I verified it works with 3.4.0.v201904051949-e1812 and Groovy 2.4 compiler, thank you! 👍 |
Today I found GROOVY-9058, but I also found that the following variation compiles with groovyc but still generates an error with Greclipse:
Consider this Java class:
and this Groovy class:
No compiler error in (A), although, strictly speaking, it should. However groovyc does not complain either. I would assume
foo
to be inferred asList<Object[]>
, given its declaration. Hovering the mouse pointer overrow
seems to confirm this and groovyc can compile this code. However, in Greclipse I get an error at (B), becauserow
is inferred asObject
even iffoo
is declared asList<Object[]>
androw
is declared asObject[]
.The text was updated successfully, but these errors were encountered: