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

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

    Details

    • Type: Bug
    • Status: Closed
    • Priority: 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)
      }
      

        Attachments

          Activity

            People

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

              Dates

              • Created:
                Updated:
                Resolved: