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-335

Nested closures : variable assignment ignored

  • Log In
  • Views
    • XML
    • Word
    • Printable

Details

  • Type: Bug Bug
  • Status: Closed Closed
  • Priority: Major Major
  • Resolution: Fixed
  • Affects Version/s: 1.0-beta-5
  • Fix Version/s: 1.0-JSR-5
  • Component/s: None
  • Labels:
    None

Description

The following code prints

1
1

it should print

1
2

class Test
{
static void main(args)
{
i = 1 // <--- remove this line and result is correct (1, 2)
c = {
i = 1
println("i = ${i}")
c1 = { i = 2 }
c1()
println("i = ${i}")
}
c()
}
}

Issue Links

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.

Activity

Ascending order - Click to sort in descending order
  • All
  • Comments
  • Work Log
  • History
  • Activity
Hide
Permalink
Bing Ran added a comment - 27/Mar/04 4:09 PM

here is another one:

i = 0

1.times {
i++
1.times { i++ println i }
println i
}

print i

I got "1" instead of "2"

Show
Bing Ran added a comment - 27/Mar/04 4:09 PM here is another one: i = 0 1.times { i++ 1.times { i++ println i } println i } print i I got "1" instead of "2"
Hide
Permalink
Sam Pullara added a comment - 23/May/04 3:49 PM

This looks related to your changes for variable scoping

Show
Sam Pullara added a comment - 23/May/04 3:49 PM This looks related to your changes for variable scoping
Hide
Permalink
blackdrag blackdrag added a comment - 25/Jan/06 6:21 PM

the new scoping fixed this problem.

Show
blackdrag blackdrag added a comment - 25/Jan/06 6:21 PM the new scoping fixed this problem.

People

  • Assignee:
    blackdrag blackdrag
    Reporter:
    Peter Brant
Vote (0)
Watch (0)

Dates

  • Created:
    27/Mar/04 12:43 PM
    Updated:
    25/Jan/06 6:21 PM
    Resolved:
    25/Jan/06 6:21 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.