Uploaded image for project: 'Groovy'
  1. Groovy
  2. GROOVY-9302

@Delegate works incorrectly with inheritance and final methods

    XMLWordPrintableJSON

Details

    • Bug
    • Status: Open
    • Major
    • Resolution: Unresolved
    • 2.5.2, 2.5.8
    • None
    • None
    • None

    Description

      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:
      @Delegate(includeTypes = [I1])
      abstract C getChild()
      
        • in child:
      @Delegate(includeTypes = [I2])
      @Override
      abstract C getChild()
      

      (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:

       

      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

      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.

      Attachments

        Activity

          People

            Unassigned Unassigned
            grv87 Basil Peace
            Votes:
            0 Vote for this issue
            Watchers:
            1 Start watching this issue

            Dates

              Created:
              Updated: