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

Unable to infer type variable of parameterized function that expects two parameters

    XMLWordPrintableJSON

Details

    Description

      I have the following program

      class A<T> {
        void m(T x) {}
      
        <T2> T m2() {
          return null;
        }
      }
      
      class Main {
        <T> void m1() {
          A<T> x = new A<T>();
          m3(m2(), x.m2()); // does not work
        }
      
        <T> T m2() {
          return null;
        }
      
        <T> void m3(T x, T y) {}
      
      }
      

      Actual behavior

      org.codehaus.groovy.control.MultipleCompilationErrorsException: startup failed:
      test.groovy: 12: [Static type checking] - Cannot call <T> Main#m3(T, T) with arguments [#T, T]
       @ line 12, column 5.
             m3(m2(), x.m2()); // does not work
             ^
      
      1 error
      

      Expected behaviour

      Compile successfully.

      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: