I'm upgrading a project from Groovy 2.4.19 to 3.0.5 with 100s of classes almost 
all @CompileStatic code on JDK 8. Upon upgrading I get compiler errors about 
static type checker knowing or not knowing anymore of objects, which is par for 
the course for any Groovy upgrade. But most of the errors I get are this:

Closure parameter with resolve strategy OWNER_FIRST passed to method with 
resolve strategy DELEGATE_FIRST

The pattern that I am using is having a method that takes a Closure, and passes 
it to Object.with:

void run(@DelegatesTo(X) Closure closure) {
  println "I'm running!"
  something.with(closure)
}

run { println prop }

So I know what OWNER_FIRST and DELEGATE_FIRST mean. And I see that the default 
in @DelegatesTo (or no annotation presumably) is OWNER_FIRST, and with clones 
the closure and sets its resolve strategy to DELEGATE_FIRST.

I can't find documentation on this message. Does the message being an error 
imply that the resolve strategy on a closure is "baked in" in CompileStatic? 
Did that change since 2.4? What is the best practice solution?

Other notes:

  1.  I build with IDEA and the default 700mb heap was not enough to build, I 
needed 5GB heap to build without OutOfMemoryError is that expected?
  2.  I'm trying to upgrade from 2.4.19 because I encountered a bug in static 
compile, in an expression x.value = someEnum, there is x.setValue(boolean) and 
x.setValue(String). 90% of the time the static compiler picks the 
setValue(String) for all such call sites in a build, 10% of the time it picks 
setValue(boolean) for all such call sites. I didn't receive any compiler errors 
on that expression as I'd expect it to be ambiguous (or at least pick same each 
time), is that expected to fail compile in Groovy 3?

Thanks,

Jason Winnebeck


Sensitivity: Internal

This email message and any attachments are for the sole use of the intended 
recipient(s). Any unauthorized review, use, disclosure or distribution is 
prohibited. If you are not the intended recipient, please contact the sender by 
reply email and destroy all copies of the original message and any attachments.

Reply via email to