Details
-
Bug
-
Status: Closed
-
Major
-
Resolution: Fixed
-
None
-
None
Description
In this code:
class Lol { def clo = { println "arg $it" }.memoize() }
a new Lol().clo("my arg") fails, even though it should work. Looking at the error message it can be seen, that the runtime tries to do a doCall, while the MemoizeFunction that is stored in clo does not have that method (instead it overrides call(Object[])). Looking at MetaClassImpl you can find the following piece of code around line 1121:
if (value instanceof Closure) { // This test ensures that value != this If you ever change this ensure that value != this Closure closure = (Closure) value; MetaClass delegateMetaClass = closure.getMetaClass(); return delegateMetaClass.invokeMethod(closure.getClass(), closure, CLOSURE_DO_CALL_METHOD, originalArguments, false, fromInsideClass); }
That code clearly tries to do doCall, instead of call. It is to be assumed that code following this does not check for both variants equally.
Proposed fix: use call instead of doCall
Attachments
Issue Links
- is duplicated by
-
GROOVY-8003 Closure without parameters memoization works only with call()
- Closed
- links to