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

incorrect scoping in closures and blocks

    XMLWordPrintableJSON

Details

    • Bug
    • Status: Closed
    • Major
    • Resolution: Fixed
    • 1.0-beta-8
    • 1.0-JSR-2
    • ast builder, lexer, parser
    • None

    Description

      i=5;
      print i;
      [1, 2, 3].each {
      item |
      int i=0;
      i+=item;
      print item;
      print i;
      };
      print i

      this example code should print 51122335 but prints 51122333. So the i in the closure is different from the i outside when inside the closure but leaving the closure the outer i will be overwritten with the inner i. As there are different scopes the outer i should still contain the old value.

      Attachments

        Issue Links

          Activity

            People

              blackdrag Jochen Theodorou
              blackdrag Jochen Theodorou
              Votes:
              0 Vote for this issue
              Watchers:
              0 Start watching this issue

              Dates

                Created:
                Updated:
                Resolved: