Details
-
Bug
-
Status: Closed
-
Major
-
Resolution: Fixed
-
2.4.7
-
None
-
None
Description
Groovy handles access to outer instance and static methods from inner classes but not nested (i.e. static) ones. The following code illustrates the problem:
class Outer { static Integer fooCount = 0 Integer barCount = 0 static void incFoo() { fooCount++ } void incBar() { barCount++ } static class Nested { static void nestedIncFoo() { incFoo() } } Inner innerFactory() { new Inner() } class Inner { } } Outer.incFoo() //Outer.Nested.nestedIncFoo() // => MME assert Outer.fooCount == 1 // but should be 2 if no MME new Outer().with { incBar() incFoo() innerFactory().with { incBar() incFoo() } assert barCount == 2 assert fooCount == 3 // but should be 4 if no MME }
After the fix, the following is expected to work:
class Outer { static Integer fooCount = 0 Integer barCount = 0 static void incFoo() { fooCount++ } void incBar() { barCount++ } static class Nested { static void nestedIncFoo() { incFoo() } } Inner innerFactory() { new Inner() } class Inner { } } Outer.incFoo() Outer.Nested.nestedIncFoo() assert Outer.fooCount == 2 new Outer().with { incBar() incFoo() innerFactory().with { incBar() incFoo() } assert barCount == 2 assert fooCount == 4 }
Basically the commented out line should work.
Attachments
Issue Links
- links to