Groovy
  1. Groovy
  2. GROOVY-3205

Cannot override toString() in a "mapOfClosures as AClass" implementation

    Details

    • Type: Bug Bug
    • Status: Closed
    • Priority: Major Major
    • Resolution: Fixed
    • Affects Version/s: 1.6-beta-2
    • Fix Version/s: 1.6-rc-1, 1.5.8, 1.7-beta-1
    • Component/s: None
    • Labels:
      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)
      }
      

        Activity

          People

          • Assignee:
            Paul King
            Reporter:
            Roshan Dawrani
          • Votes:
            0 Vote for this issue
            Watchers:
            0 Start watching this issue

            Dates

            • Created:
              Updated:
              Resolved:

              Development