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

closures don't find variables in a delegate if the variable written to before it's read

    XMLWordPrintableJSON

Details

    • Bug
    • Status: Closed
    • Major
    • Resolution: Fixed
    • 1.0-beta-5
    • 1.0-JSR-4
    • class generator
    • None

    Description

      class C {
      static main(args) {
      env = ['in':2, 'out':0]
      c =

      {out = in * 2 }

      c.setDelegate(env)
      c()
      println env.in
      println env.out
      }
      }

      produces
      2
      0

      class C {
      static main(args) {
      env = ['in':2, 'out':0]
      c =

      {x = out; out = in * 2 }

      c.setDelegate(env)
      c()
      println env.in
      println env.out
      }
      }

      produces
      2
      4

      the first output is wrong

      Attachments

        Issue Links

          Activity

            People

              tug John Wilson
              tug John Wilson
              Votes:
              0 Vote for this issue
              Watchers:
              0 Start watching this issue

              Dates

                Created:
                Updated:
                Resolved: