Details
-
Type:
Bug
-
Status:
Closed
-
Priority:
Major
-
Resolution: Fixed
-
Affects Version/s: None
-
Fix Version/s: 1.0-JSR-4
-
Component/s: None
-
Labels:None
-
Environment:Mac OS X 10.3.3, java 1.4.2
Description
I posted this on the mailing lists, but got no reply, so I will create a bug report:
I am having problems with a child class accessing a super
class's fields. Here is the simplest code that demonstrate this
problem:
A.groovy:
class A {
public aa
A() { aa = "this is not set!" }
doit() {
println aa
}
}
B.groovy:
class B extends A {
B() {
//super() /* doesn't matter if this is here or not */
aa = "now B has set it!"
doit()
}
static void main(args) {
bb = new B()
}
}
Now when I run:
$ groovy B.groovy
I get:
this is not set.
So it seems that B set his own copy of aa instead of the super
class's aa. If I changed the line:
aa = "now B has set it!"
to:
this.aa = "now B has set it!"
it works.
Issue Links
- is depended upon by
-
GROOVY-754
scoping
-
this should be fixed by the jsr parser since it requires a "def " if you want to declare a variable in classes