[ https://issues.apache.org/jira/browse/GROOVY-3917?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel ]
Eric Milles updated GROOVY-3917: -------------------------------- Description: I have a type A that defines the {{getProperty}} magic method. It is declared as a delegate in a class called B. The {{getProperty}} method is not redefined in B so whenever {{getProperty}} is called on an instance of B it delegates the request to A which then handles the request as expected. If I then have a class C that declares a delegate of type B and also does not redefine the {{getProperty}} method, I would expect that when you call {{getProperty}} on an instance of C that it would delegate to its instance of type B, which would in turn delegate the request to its instance of type A and the request would be handled. Unfortunately, this does not happen. Class C says it does not have a property with the name requested. If I then define {{getProperty}} in C but simply return {{b.getProperty(somePropertyName)}} in the method (explicitly defining the delegation) then groovy handles the delegation. Does this mean that delegation only works 1 level deep? See example below where C does delegation of {{getProperty}} explicitly (this works) {code:groovy} class C { @Delegate B b = new B() public getProperty(String name) { return b.getProperty(name) } static void main(args) { def c = new C() System.out.println(c.hello) } } class B { @Delegate A a = new A() } class A { public getProperty(String name) { return name } } {code} ... and implicitly (this doesn't work) {code:groovy} class C { @Delegate B b = new B() static void main(args) { def c = new C() System.out.println(c.hello) //throws an unknown property exception } } class B { @Delegate A a = new A() } class A { public getProperty(String name) { return name } } {code} was: I have a type A that defines the getProperty magic method. It is declared as a delegate in a class called B. The getProperty method is not redefined in B so whenever getProperty is called on an instance of B it delegates the request to A which then handles the request as expected. If I then have a class C that declares a delegate of type B and also does not redefine the getProperty method, I would expect that when you call getProperty on an instance of C that it would delegate to its instance of type B, which would in turn delegate the request to its instance of type A and the request would be handled. Unfortunately, this does not happen. Class C says it does not have a property with the name requested. If I then define getProperty in C but simply return b.getProperty(somePropertyName) in the method (explicitly defining the delegation) then groovy handles the delegation. Does this mean that delegation only works 1 level deep? See example below where C does delegation of getProperty explicitly (this works) class C { @Delegate B b = new B() public getProperty(String name) { return b.getProperty(name) } static void main(args) { def c = new C() System.out.println(c.hello) } } class B { @Delegate A a = new A() } class A { public getProperty(String name) { return name } } ... and implicitly (this doesn't work) class C { @Delegate B b = new B() static void main(args) { def c = new C() System.out.println(c.hello) //throws an unknown property exception } } class B { @Delegate A a = new A() } class A { public getProperty(String name) { return name } } > getProperty isn't delegated more than 1 level deep > -------------------------------------------------- > > Key: GROOVY-3917 > URL: https://issues.apache.org/jira/browse/GROOVY-3917 > Project: Groovy > Issue Type: Bug > Components: groovy-runtime > Affects Versions: 1.6.4 > Environment: Mac OSX, 10.5.8 > Reporter: luke painter > Priority: Major > > I have a type A that defines the {{getProperty}} magic method. It is > declared as a delegate in a class called B. The {{getProperty}} method is > not redefined in B so whenever {{getProperty}} is called on an instance of B > it delegates the request to A which then handles the request as expected. If > I then have a class C that declares a delegate of type B and also does not > redefine the {{getProperty}} method, I would expect that when you call > {{getProperty}} on an instance of C that it would delegate to its instance of > type B, which would in turn delegate the request to its instance of type A > and the request would be handled. > Unfortunately, this does not happen. Class C says it does not have a > property with the name requested. If I then define {{getProperty}} in C but > simply return {{b.getProperty(somePropertyName)}} in the method (explicitly > defining the delegation) then groovy handles the delegation. Does this mean > that delegation only works 1 level deep? > See example below where C does delegation of {{getProperty}} explicitly (this > works) > {code:groovy} > class C { > @Delegate B b = new B() > public getProperty(String name) { > return b.getProperty(name) > } > static void main(args) { > def c = new C() > System.out.println(c.hello) > } > } > class B { > @Delegate A a = new A() > } > class A { > public getProperty(String name) { > return name > } > } > {code} > ... and implicitly (this doesn't work) > {code:groovy} > class C { > @Delegate B b = new B() > static void main(args) { > def c = new C() > System.out.println(c.hello) //throws an unknown property exception > } > } > class B { > @Delegate A a = new A() > } > class A { > public getProperty(String name) { > return name > } > } > {code} -- This message was sent by Atlassian Jira (v8.3.4#803005)