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

The delegate is ignored when resolving names in a closure in a script

Attach filesAttach ScreenshotVotersWatch issueWatchersCreate sub-taskLinkCloneUpdate Comment AuthorReplace String in CommentUpdate Comment VisibilityDelete Comments
    XMLWordPrintableJSON

Details

    • Bug
    • Status: Closed
    • Major
    • Resolution: Fixed
    • 1.0-beta-5
    • 1.0-RC-1
    • None

    Description

      Closure tries to rsolve a method ot poperty name by first using the MetaClass, second using the owner and thirdly using the delegate. However InvokerHelper.getProperty(owner, property) always returns null if the owner is a script.

      This can produce subtle bugs (e.g. when using an Expando object in a script.

      exp = new Expando()
      exp.a = "x"
      println exp.a
      exp.b =

      {println "called"}

      exp.b()
      exp.c = {println "a = ${this.a}"}
      exp.c()
      exp.c = {println "a = ${this.a}"}
      exp.c.setDelegate(exp)
      exp.c()

      produces different output in a script and a program

      Attachments

        Issue Links

        Activity

          This comment will be Viewable by All Users Viewable by All Users
          Cancel

          People

            blackdrag Jochen Theodorou
            tug John Wilson
            Votes:
            1 Vote for this issue
            Watchers:
            0 Start watching this issue

            Dates

              Created:
              Updated:
              Resolved:

              Slack

                Issue deployment