You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@groovy.apache.org by "Basil Peace (Jira)" <ji...@apache.org> on 2019/11/03 18:18:00 UTC

[jira] [Comment Edited] (GROOVY-9302) @Delegate works incorrectly with inheritance and final methods

    [ https://issues.apache.org/jira/browse/GROOVY-9302?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=16965701#comment-16965701 ] 

Basil Peace edited comment on GROOVY-9302 at 11/3/19 6:17 PM:
--------------------------------------------------------------

IMO, {{final}} modifier should be handled differently. {{@Delegate should be completely ignore final}} on delegated method and either mark all delegated methods as {{final}}, or have separate option for that.


was (Author: grv87):
IMO, {{final}} modifier should be handled differently. {{@Delegat}}e should be completely ignore {{final}} on delegated method and either mark all delegated methods as {{final}}, or have separate option for that.

> @Delegate works incorrectly with inheritance and final methods
> --------------------------------------------------------------
>
>                 Key: GROOVY-9302
>                 URL: https://issues.apache.org/jira/browse/GROOVY-9302
>             Project: Groovy
>          Issue Type: Bug
>    Affects Versions: 2.5.2, 2.5.8
>            Reporter: Basil Peace
>            Priority: Major
>
> In the following situation:
>  * Two class hierarchies: Child1 <|-- Child2 and Parent1 <|-- Parent0
>  * Classes from the second hierarchy delegate to the first ones with constructions:
>  ** in parent:
> {code:java}
> @Delegate(includeTypes = [I1])
> abstract C getChild()
> {code}
>  ** in child:
> {code:java}
> @Delegate(includeTypes = [I2])
> @Override
> abstract C getChild()
> {code}
> (in other words, all calls are delegated to the same instance, just on different levels of hierarchy)
>  * Methods in the first hierarchy are marked {{final}}
> compiler gives an error:
>  
> {noformat}
> org.codehaus.groovy.control.MultipleCompilationErrorsException: startup failed:
> com\example\Parent0.groovy: -1: You are not allowed to override the final method method1() from class 'com.example.Parent1'.
>  @ line -1, column -1.
> 1 error{noformat}
> Repository reproducing it: [https://github.com/grv87/groovy-delegate-and-inheritance]
>  
> Error presence depends on compilation order. If I rename {{Parent0}} to {{Parent2}}, error disappears.
> So, as I see, the problem is that when {{@Delegate}} is applied to {{Parent0}}, it doesn't detect that some methods are already added by another {{@Delegate}} to it's super, {{Parent1}}.
> Removing {{final}} modifier just hides the problem, Parent0 still have methods overriding Parent1, which is unnecessary.



--
This message was sent by Atlassian Jira
(v8.3.4#803005)