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

Closures and the handling of variables

    XMLWordPrintableJSON

Details

    • Bug
    • Status: Closed
    • Major
    • Resolution: Duplicate
    • 1.0-beta-5
    • 1.0-JSR-3
    • 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

        Activity

          People

            jstrachan James Strachan
            nurulc nurul choudhury
            Votes:
            0 Vote for this issue
            Watchers:
            0 Start watching this issue

            Dates

              Created:
              Updated:
              Resolved: