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

Problem With CompileStatic And Interface Methods In Abstract Subclass

    XMLWordPrintableJSON

Details

    • Bug
    • Status: Closed
    • Major
    • Resolution: Fixed
    • 2.4.3
    • 2.4.4
    • Compiler
    • None

    Description

      The attached abstractcompilestatic.zip contains the following:

      src/main/groovy/demo/SomeInterface.groovy
      package demo
      
      interface SomeInterface {
          void someInterfaceMethod()
      }
      
      src/main/groovy/demo/AbstractSuperClass.groovy
      package demo
      
      abstract class AbstractSuperClass implements SomeInterface {}
      
      src/main/groovy/demo/AbstractSubClass.groovy
      package demo
      
      import groovy.transform.CompileStatic
      
      @CompileStatic
      abstract class AbstractSubClass extends AbstractSuperClass {
      
          void someMethod() {
              someInterfaceMethod()
          }
      }
      

      The code will not compile.

       $ ./gradlew clean compileGroovy
      :clean
      :compileJava UP-TO-DATE
      :compileGroovy
      startup failed:
      /Users/jeff/abstractcompilestatic/src/main/groovy/demo/AbstractSubClass.groovy: 9: [Static type checking] - Cannot find matching method demo.AbstractSubClass#someInterfaceMethod(). Please check if the declared type is right and if the method exists.
       @ line 9, column 9.
                 someInterfaceMethod()
                 ^
      
      1 error
      
      :compileGroovy FAILED
      
      FAILURE: Build failed with an exception.
      
      * What went wrong:
      Execution failed for task ':compileGroovy'.
      > Compilation failed; see the compiler error output for details.
      
      * Try:
      Run with --stacktrace option to get the stack trace. Run with --info or --debug option to get more log output.
      
      BUILD FAILED
      
      Total time: 4.045 secs
      

      If the AbstractSubClass is modified to implement the interface as shown below the code will compile:

      src/main/groovy/demo/AbstractSubClass.groovy
      package demo
      
      import groovy.transform.CompileStatic
      
      @CompileStatic
      abstract class AbstractSubClass extends AbstractSuperClass implements SomeInterface {
      
          void someMethod() {
              someInterfaceMethod()
          }
      }
      

      Attachments

        1. abstractcompilestatic.zip
          53 kB
          Allen Arakaki
        2. abstractcompilestatic.zip
          50 kB
          Jeff Scott Brown

        Issue Links

          Activity

            People

              paulk Paul King
              jeffscottbrown Jeff Scott Brown
              Votes:
              1 Vote for this issue
              Watchers:
              5 Start watching this issue

              Dates

                Created:
                Updated:
                Resolved: