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

Groovy fails to set field without qualifying with "this"

  • Log In
  • Views
    • XML
    • Word
    • Printable

Details

  • Type: Bug Bug
  • Status: Closed Closed
  • Priority: Minor Minor
  • Resolution: Won't Fix
  • Affects Version/s: 1.0-JSR-1
  • Fix Version/s: 1.0-JSR-5
  • Component/s: None
  • Labels:
    None

Description

Consider the following code:

def x = 5

def test() {
x = 6
}

test()
println x

The expected result is 6.
The actual result is 5.
Workaround: use the "this" keyword i.e. this.x = 6

Issue Links

depends upon

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

  • All
  • Comments
  • Work Log
  • History
  • Activity
Hide
Permalink
blackdrag blackdrag added a comment - 19/Jan/06 7:35 PM

a variable that is declared is not part of the binding. so "def x=5" does declare a local variable. The method does use the binding, so bind.x==6. After the method x is the local variable again, so x is 5 .

Show
blackdrag blackdrag added a comment - 19/Jan/06 7:35 PM a variable that is declared is not part of the binding. so "def x=5" does declare a local variable. The method does use the binding, so bind.x==6. After the method x is the local variable again, so x is 5 .

People

  • Assignee:
    blackdrag blackdrag
    Reporter:
    Jonathan Aquino
Vote (0)
Watch (0)

Dates

  • Created:
    19/Apr/05 7:03 PM
    Updated:
    19/Jan/06 7:35 PM
    Resolved:
    19/Jan/06 7:35 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.