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

Problem with @CompileStatic, generic types, and varags

    XMLWordPrintableJSON

Details

    • Bug
    • Status: Closed
    • Major
    • Resolution: Fixed
    • 2.4.4
    • None
    • groovy-jdk
    • None

    Description

      Similar to GROOVY-7182, groovyc fails to handle generic types if a class uses @CompileStatic and the generically typed method has a varargs parameter. Removal of @CompileStatic or the varargs parameter eliminates the compile error.

      (Clarification: methodOn need not be defined in the @CompileStatic class. In the original case, the method was ControllerLinkBuilder#methodOn from Spring's HATEOAS library.)

      VarArgsGenericsCase.groovy
      import groovy.transform.CompileStatic
      
      @CompileStatic
      class VarArgsGenericsCase {
      
          def markus(String name) {
              methodOn(VarArgsGenericsCase).markus(name)
          }
      
          static <T> T methodOn(Class<T> clazz, Object... parameters) {
              return clazz.newInstance()
          }
      }
      
      org.codehaus.groovy.control.MultipleCompilationErrorsException: startup failed:
      VarArgsGenericsCase.groovy: 7: [Static type checking] - Cannot find matching method java.lang.Object#markus(java.lang.String). Please check if the declared type is correct and if the method exists.
       @ line 7, column 9.
                 methodOn(VarArgsGenericsCase).markus(name)
                 ^
      
      1 error
      

      Attachments

        Issue Links

          Activity

            People

              emilles Eric Milles
              roxton Adam Augusta
              Votes:
              0 Vote for this issue
              Watchers:
              1 Start watching this issue

              Dates

                Created:
                Updated:
                Resolved: