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

Static type checking fails when compiling against a Java8 interface with inherited methods

    XMLWordPrintableJSON

Details

    Description

      Create classes.java:

      interface I {
          R[] method();
      }
      
      interface I2 extends I {
          R2[] method();
      }
      
      interface R {}
      interface R2 extends R {}
      

      compile it with JDK 8 javac.

      Then create usage.groovy:

      import groovy.transform.CompileStatic
      
      @CompileStatic
      class Gr {
          R2[] x(I2 i) {
             return i.method();
          }
      }
      

      Compile it with groovyc (also run with Java8) with the classes from previous compilation in the classpath. Compilation fails:

      usage.groovy: 6: [Static type checking] - Reference to method is ambiguous. Cannot choose between [R2[] I2#method(), R[] I2#method()]
       @ line 6, column 15.
                return i.method();
                       ^
      
      1 error
      

      Originally reported as https://youtrack.jetbrains.com/issue/IDEA-148973

      Attachments

        Issue Links

          Activity

            People

              daniel_sun Daniel Sun
              gromopetr Peter Gromov
              Votes:
              0 Vote for this issue
              Watchers:
              7 Start watching this issue

              Dates

                Created:
                Updated:
                Resolved: