Details
-
Bug
-
Status: Closed
-
Major
-
Resolution: Fixed
-
1.6.3
-
None
-
None
Description
When you call setDelegate() on a curried closure, this acts to set the delegate of the underlying base closure. However, even after the delegate has been changed in this way, getDelegate still returns the original delegate (typically the containing scope of the .curry() call).
Also, CurriedClosure does not pass setResolveStrategy or getResolveStrategy to the base closure. This can lead to unexpected behaviour:
void hello(who) { println "Hello $who" } def c = { x -> hello(x) } c.call("Ian") // prints "Hello Ian" c.delegate = null c.resolveStrategy = Closure.DELEGATE_ONLY c.call("Ian") // MissingMethodException (as expected)
Constrast this with:
void hello(who) { println "Hello $who" } def c = { x -> hello(x) } def d = c.curry("Ian") d.call() // prints "Hello Ian" d.delegate = null assert d.delegate != null // succeeds! d.resolveStrategy = Closure.DELEGATE_ONLY d.call() // Also prints "Hello Ian" - no MME
Is this behaviour a design decision or is it something that can be changed?
The particular case that drew my attention to this problem was using curried closures for actions in a Grails web flow, but any DSL that manipulates the resolveStrategy would be affected in a similar way.
NB I've tested this with groovy 1.6.3 (as supplied by grails 1.1.1) but CurriedClosure still looks the same in the latest svn head so I presume its behaviour is unchanged.