Uploaded image for project: 'Groovy'
  1. Groovy
  2. GROOVY-3205

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

    XMLWordPrintableJSON

Details

    • Bug
    • Status: Closed
    • Major
    • Resolution: Fixed
    • 1.6-beta-2
    • 1.6-rc-1, 1.5.8, 1.7-beta-1
    • 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)
      }
      

      Attachments

        Activity

          People

            paulk Paul King
            roshandawrani Roshan Dawrani
            Votes:
            0 Vote for this issue
            Watchers:
            0 Start watching this issue

            Dates

              Created:
              Updated:
              Resolved: