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

Static Type Checking selects wrong method for abstract method call check

    XMLWordPrintableJSON

Details

    • Bug
    • Status: Closed
    • Major
    • Resolution: Fixed
    • 4.0.7
    • 4.0.8, 3.0.20
    • Static Type Checker
    • None

    Description

      Consider following code:

      @CompileStatic
      class E extends BImpl {
          @Override
          void a() {
              super.a();
          }
          static void main(args) { }
      }
      interface A {
          void a()
      }
      interface B extends A {
          @Override
          void a()
      }
      class AImpl implements A {
          @Override
          void a() {
          }
      }
      class BImpl extends AImpl implements B {
      } 

      Compiling it will fail with the error
      [Static type checking] - Abstract method a() cannot be called directly

      However, when running it without @CompileStatic or when writing similar code in Java, it will select the non-abstract method from AImpl instead.

      It seems like this is a problem in the code to choose the best method here: https://github.com/apache/groovy/blob/ea6ba7c6fcfefe3d8abdfbb6e20a44b1ebb8823e/src/main/java/org/codehaus/groovy/transform/stc/StaticTypeCheckingSupport.java#L1091

      The distance from BImpl to B to the interface is less than (1) the distance to AImpl (4), therefore the abstract method is chosen as best method.

      This originally happened when extending AbstractSet and calling super.addAll(...).

      Attachments

        Issue Links

          Activity

            People

              emilles Eric Milles
              sirywell Hannes Greule
              Votes:
              0 Vote for this issue
              Watchers:
              2 Start watching this issue

              Dates

                Created:
                Updated:
                Resolved: