-
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
CompileStatic: Spurious errors on equals method shown in eclipse editor and not in Problems #1209
Comments
There is a block in MethodNode adapter = StaticCompilationTransformer.BYTECODE_BINARY_ADAPTERS.get(operationType);
if (adapter != null) {
Expression sba = classX(StaticCompilationTransformer.BYTECODE_ADAPTER_CLASS);
call = callX(sba, "compareEquals", args(expr, right));
call.setMethodTarget(adapter);
} else {
...
} I think it is supposed to be "compareEqual" -- excerpt from ScriptBytecodeAdapter.java: public static boolean compareEqual(Object left, Object right) { |
Looking at the "compareTo" transformation (also in MethodCallExpression call;
Expression left = staticCompilationTransformer.transform(leftExpression);
Expression right = staticCompilationTransformer.transform(rightExpression);
if (operationType == Types.COMPARE_TO
&& findType(leftExpression).implementsInterface(ClassHelper.COMPARABLE_TYPE)
&& findType(rightExpression).implementsInterface(ClassHelper.COMPARABLE_TYPE)) {
call = callX(left, "compareTo", args(right));
call.setImplicitThis(false);
call.setMethodTarget(COMPARE_TO_METHOD);
call.setSourcePosition(bin); |
Wow, thanks for the fast followup 👍 I will wait for a snapshot to include this and then give it a try (unless that's not appropriate at this point?). |
ready to test |
Are you using Groovy 3 or 2.5? I did not port the whole fix to 2.5 because it requires a bit more reogranizing. |
Ah - I'm stuck on 2.5 sorry, should have mentioned. Thanks for working on this so fast! |
Is there any more context you can provide? Maybe a small sample project? |
I think I have it. "x == null" or "x != null" can be converted to |
I am wondering if you have a case of extra processing somewhere. How are you enabling static type checking and/or static compilation? |
Sorry for the lack of context - it's actually an open source project so you can see the full source context for one of the above problems here: As shown there, the static compilation is enabled by the |
NB: as followup - just did the experiment of applying |
there should be a new snapshot available for testing |
That fixed the rest of the errors - thanks so much for the work on this! 👍 |
Is it possible for you to setup a separate eclipse instance with 3.9.0.RELEASE? If so, could you check if removing the default value from the parameter makes the error go away? @CompileStatic
void outputBlock(int endPos=-1) { // try remove "=-1"
blockCount++
if(endPos>=0)
block.end = endPos
if(block.end < block.start)
assert false
blocks.add(block)
if(this.gapProcessor != null)
this.gapProcessor.sendTo(block)
block = null
} |
I am having a lot of trouble nailing down when this happens and doesn't happen, and unfortunately
so far don't have a simple example I can share.
The problem is always in an
equals
comparison and occurs on the base language types like Object, String and null - here's an example where it claims it cannot compare two strings:Here's another example where it can't compare something to null:
Sorry I don't yet have a reproducible example - it seems to be sporadic enough that I can't yet make a simple example of it. However I wanted to log this in case there's a way to fix it anyway, or if other people are encountering it.
I was encountering this using the stable release of 3.9.0 and now upgraded to the snapshot release of 4.0:
Both of them seem to have the same behaviour.
The text was updated successfully, but these errors were encountered: