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

STC instantiates type variable with a wrong type when calling an instance method of the same class

    XMLWordPrintableJSON

Details

    Description

      I have the following program

      import java.util.function.Function;
      
      class A<T> {
        T y;
        void foo(T x, Function<T, T> func) {
          foo((true) ? x : y, func)
        }
      }
      
      

      Actual behavior

      org.codehaus.groovy.control.MultipleCompilationErrorsException: startup failed:
      test.groovy: 6: [Static type checking] - Cannot call A#foo(java.lang.Object, java.util.function.Function<java.lang.Object, java.lang.Object>) with arguments [java.lang.Object<T>, java.util.function.Function<T, T>]
       @ line 6, column 5.
             foo((true) ? x : y, func)
             ^
      
      1 error
      

      Expected behaviour

      Compile successfully

      Note: If replace `Function<T, T> func` with `Supplier<T> func`, the code compiles as expected.

      Tested against master.

      Attachments

        Activity

          People

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

            Dates

              Created:
              Updated:
              Resolved: