[
https://issues.apache.org/jira/browse/GROOVY-7480?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=17141675#comment-17141675
]
Eric Milles commented on GROOVY-7480:
-------------------------------------
When making an implicit-this method call from within a closure, methods on
Closure itself take precedence. This is so you can call "getDelegate()" or
"trampoline()" for example. In this case, you are effectively calling
"c.leftShift('*')", since leftShift is a method implemented by
groovy.lang.Closure.
You can add a "delegate." or "getDelegate()." qualifier to your leftShift call
to direct it away from Closure.
{code:java}
/**
* Alias for calling a Closure for non-closure arguments.
* <p>
* Typical usage:
* <pre class="groovyTestCase">
* def times2 = { a {@code ->} a * 2 }
* def add3 = { a {@code ->} a + 3 }
* assert add3 {@code <<} times2 {@code <<} 3 == 9
* </pre>
*
* @param arg the argument to call the closure with
* @return the result of calling the Closure
*/
public V leftShift(final Object arg) {
return call(arg);
}
{code}
> ClosureMetaClass wrong routing calls logic
> ------------------------------------------
>
> Key: GROOVY-7480
> URL: https://issues.apache.org/jira/browse/GROOVY-7480
> Project: Groovy
> Issue Type: Bug
> Components: groovy-runtime
> Affects Versions: 2.4.2
> Reporter: Paolo Piersanti
> Priority: Major
>
> Setting up the resolve strategy to Closure.DELEGATE_FIRST does not
> get the delegate looked up at first. For instance:
> target = 'aTarget'
> c = new GroovyShell().evaluate("{ -> leftShift('*') }");
> c.resolveStrategy = Closure.DELEGATE_FIRST
> c.delegate = target
> c.call()
> results in
> groovy.lang.MissingMethodException: No signature of method:
> Script1$_run_closure1.doCall() is applicable for argument types:
> (java.lang.String) values: [*]
> Possible solutions: doCall(), findAll(), findAll(),
> isCase(java.lang.Object), isCase(java.lang.Object)
> at Script1$_run_closure1.doCall(Script1.groovy:1)
> at ConsoleScript33.run(ConsoleScript33:5)
--
This message was sent by Atlassian Jira
(v8.3.4#803005)