Details
-
Bug
-
Status: Closed
-
Major
-
Resolution: Fixed
-
1.6-beta-2
-
None
-
None
Description
I am unable to override toString() when I coerce a map-of-closures as a class. This works on 1.5.8 but not on 1.6-rc-1 and 1.7-beta-1 branches. The code below highlights the issue:
class GroovyXXXXBug extends GroovyTestCase { def void testOverrideToStringInMapOfClosuresAsClass() { def subObj = [ toString: { "Sub toString()" } ] as GroovyXXXXBugBase assert subObj.toString() == "Sub toString()" } } class GroovyXXXXBugBase { String toString() { "Base toString()" } }
The code generated by ProxyGenerator for the overridden toString() method looks as below, which is not correct because of the extra args parameter and because of it the toString() gets overloaded and not overridden:
def toString(Object[] args) { this.@closureMap['toString'] (*args) }