You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@groovy.apache.org by "Eric Milles (Jira)" <ji...@apache.org> on 2023/11/03 18:25:00 UTC

[jira] [Updated] (GROOVY-8146) Callable properties of closure delegate cannot be called implicitly

     [ https://issues.apache.org/jira/browse/GROOVY-8146?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel ]

Eric Milles updated GROOVY-8146:
--------------------------------
    Language: groovy

> Callable properties of closure delegate cannot be called implicitly
> -------------------------------------------------------------------
>
>                 Key: GROOVY-8146
>                 URL: https://issues.apache.org/jira/browse/GROOVY-8146
>             Project: Groovy
>          Issue Type: Improvement
>          Components: groovy-runtime
>    Affects Versions: 2.5.0-alpha-1
>            Reporter: David Attia
>            Priority: Major
>
> Where a closure's delegate has a property with a call method, the method cannot be called inline.
> {noformat}
> 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()
>     }
> }
> {noformat}
> 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:
> {noformat}
> 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)
> {noformat}



--
This message was sent by Atlassian Jira
(v8.20.10#820010)