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

@CompileStatic complains when trying to call generic methods with different generic type parameter names

    XMLWordPrintableJSON

    Details

      Description

      @groovy.transform.CompileStatic
      class Foo {
      	String method() {
      		return callT('abc')
      	}
      
          private <T> T callT(T t) {
      		return callV(t)
      	}
      
      	private <V> V callV(V v) {
      		return v
      	}
      }
      
      println new Foo().method()
      

      Without @CompileStatic annotation, it outputs 'abc'.

      With @CompileStatic annotation, it generates a compilation error:

      org.codehaus.groovy.control.MultipleCompilationErrorsException: startup failed:
      /Users/abrown/tmp/groovy/generics.groovy: 8: [Static type checking] - Cannot call Foo#callV(java.lang.Object <V>) with arguments [java.lang.Object <T>]
       @ line 8, column 10.
         		return callV(t)
                  ^
      
      1 error
      

        Attachments

          Activity

            People

            • Assignee:
              blackdrag Jochen Theodorou
              Reporter:
              acourtneybrown Adam Brown
            • Votes:
              4 Vote for this issue
              Watchers:
              4 Start watching this issue

              Dates

              • Created:
                Updated:
                Resolved: