jira.codehaus.org

  • Log In Access more options
    • Online Help
    • Keyboard Shortcuts
    • About JIRA
    • JIRA Credits
    • What?s New
  • Dashboards Access more options (Alt+d)
  • Projects Access more options (Alt+p)
  • Issues Access more options (Alt+i)
  • groovy
  • GROOVY-918

Cannot set outside variables from within nested closures

  • Log In
  • Views
    • XML
    • Word
    • Printable

Details

  • Type: Bug Bug
  • Status: Closed Closed
  • Priority: Major Major
  • Resolution: Fixed
  • Affects Version/s: 1.0-JSR-2
  • Fix Version/s: 1.0-JSR-5
  • Component/s: class generator
  • Labels:
    None
  • Environment:
    HEAD
  • Testcase included:
    yes

Description

You cannot set variables more than one closure aware from their scope:

def t = 2;
[1].each {
[1].each { t = 1; }
}
println t;

This currently prints 0.

Issue Links

duplicates

Bug - A problem which impairs or prevents the functions of the product. GROOVY-534 Nested closures - variable scope problem

  • Major - Major loss of function.
  • Closed - The issue is considered finished, the resolution is correct. Issues which are not closed can be reopened.
is depended upon by

Task - A task that needs to be done. GROOVY-754 scoping

  • Major - Major loss of function.
  • Closed - The issue is considered finished, the resolution is correct. Issues which are not closed can be reopened.

Task - A task that needs to be done. GROOVY-764 closures

  • Major - Major loss of function.
  • Closed - The issue is considered finished, the resolution is correct. Issues which are not closed can be reopened.

Activity

Ascending order - Click to sort in descending order
  • All
  • Comments
  • Work Log
  • History
  • Activity
Hide
Permalink
Sam Pullara added a comment - 23/Jun/05 1:29 PM

It's really bad, here is another example:

def t = 2;
[1].each {
[1].each {println t; t = 1; }
println t;
}
println t;

This prints 2,2,2.

Show
Sam Pullara added a comment - 23/Jun/05 1:29 PM It's really bad, here is another example: def t = 2; [1].each { [1].each {println t; t = 1; } println t; } println t; This prints 2,2,2.
Hide
Permalink
blackdrag blackdrag added a comment - 24/Jun/05 6:24 AM

I added some links, also note that this issue duplicates GROOVY-534

Show
blackdrag blackdrag added a comment - 24/Jun/05 6:24 AM I added some links, also note that this issue duplicates GROOVY-534
Hide
Permalink
Wang Bin added a comment - 11/Jul/05 8:05 PM

I think this is the most serious bug, and we should fix it in groovy 1.0

Show
Wang Bin added a comment - 11/Jul/05 8:05 PM I think this is the most serious bug, and we should fix it in groovy 1.0
Hide
Permalink
blackdrag blackdrag added a comment - 19/Jan/06 7:06 PM

the first program prints now 2 and the second 211
I think that is what should be expected

Show
blackdrag blackdrag added a comment - 19/Jan/06 7:06 PM the first program prints now 2 and the second 211 I think that is what should be expected

People

  • Assignee:
    blackdrag blackdrag
    Reporter:
    Sam Pullara
Vote (0)
Watch (0)

Dates

  • Created:
    23/Jun/05 1:27 PM
    Updated:
    19/Jan/06 7:06 PM
    Resolved:
    19/Jan/06 7:06 PM
  • Atlassian JIRA (v5.0.4#731-sha1:3aa7374)
  • Report a problem
  • Powered by a free Atlassian JIRA open source license for Codehaus. Try JIRA - bug tracking software for your team.