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

Unable to infer the type parameter of a parameterized function

    XMLWordPrintableJSON

Details

    • Bug
    • Status: Closed
    • Major
    • Resolution: Fixed
    • None
    • 4.0.0-beta-2
    • Static Type Checker
    • None

    Description

      I have the following program

      class A {
          static <T> T foo() {
              return null;
          }
      }
      class Test<T> {
          void bar() {
              T x = A.foo();
          }
      }
      

      Actual Behaviour

      org.codehaus.groovy.control.MultipleCompilationErrorsException: startup failed:
      groovy11.groovy: 9: [Static type checking] - Cannot assign value of type #T to variable of type T
       @ line 9, column 15.
                 T x = A.foo();
                       ^1 error
      
      

      Expected Behaviour

      Compile successfully

       

      I don't know however, if this is a limitation of the inference engine of groovyc or a bug. Note that the Java compiler compiles the above program successfully. Also note that if I replace "T x = A.foo()" with "String x = A.foo()", groovyc compiles the updated program.

       

      Attachments

        Issue Links

          Activity

            People

              emilles Eric Milles
              theosot Thodoris Sotiropoulos
              Votes:
              0 Vote for this issue
              Watchers:
              2 Start watching this issue

              Dates

                Created:
                Updated:
                Resolved: