Details
-
Bug
-
Status: Closed
-
Major
-
Resolution: Fixed
-
2.5.0-alpha-1
-
None
-
None
Description
Where a closure's delegate has a property with a call method, the method cannot be called inline.
class DelegateMember { void call(@DelegatesTo(DelegateMember) Closure closure) { closure.delegate = this closure.call() } void sayHello() { println 'hello' } } class Delegate { DelegateMember delegateMember = new DelegateMember() } void callAndDelegate(@DelegatesTo(Delegate) Closure closure) { closure.delegate = new Delegate() closure.call() } callAndDelegate { delegateMember { // intended get and call of delegateMember sayHello() } }
In the above example, I'm hoping for the commented line to call the synthetic getter for delegateMember and to then call it with the closure parameter (code block).
My IDE (IntelliJ IDEA 2016.2.2) interprets this code in the way I hoped the runtime would (asking to go to the declaration of sayHello from the call within the closure takes me to the declaration of the sayHello method), but execution fails with message:
Caught: groovy.lang.MissingMethodException: No signature of method: scratch_groovy.delegateMember() is applicable for argument types: (scratch_groovy$_run_closure1_closure2) values: [scratch_groovy$_run_closure1_closure2@6b46a226] groovy.lang.MissingMethodException: No signature of method: scratch_groovy.delegateMember() is applicable for argument types: (scratch_groovy$_run_closure1_closure2) values: [scratch_groovy$_run_closure1_closure2@6b46a226] at scratch_groovy$_run_closure1.doCall(scratch_groovy.groovy:21) at scratch_groovy$_run_closure1.doCall(scratch_groovy.groovy) at scratch_groovy.callAndDelegate(scratch_groovy.groovy:17) at scratch_groovy$callAndDelegate.callCurrent(Unknown Source) at scratch_groovy.run(scratch_groovy.groovy:20) at com.intellij.rt.execution.application.AppMain.main(AppMain.java:147) at com.intellij.rt.execution.CommandLineWrapper.main(CommandLineWrapper.java:48)
Attachments
Issue Links
- is related to
-
GROOVY-3395 calling binding variable as function fails to try object's call() method
- Closed