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:08:00 UTC

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

Basil Peace created GROOVY-9302:
-----------------------------------

             Summary: @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.8, 2.5.2
            Reporter: Basil Peace


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)