Details
-
Type:
Bug
-
Status:
Closed
-
Priority:
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
-
GROOVY-754
scoping
-
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 .