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

Type variable substitution does not work properly on parameterized function's return type

    XMLWordPrintableJSON

Details

    Description

      I have the following program

      class A<T1, T2> {
        void m1(T1 x) {}
      
        void test() {
          var x = new B();
          T2 y = null;
          (new A<T2, T2>()).m1(x.m2(y));
        }
        
      }
      
      class B {
        <X, Y> X m2(Y x) { return null; }
      }
      

      Actual behaviour

      org.codehaus.groovy.control.MultipleCompilationErrorsException: startup failed:
      test.groovy: 8: [Static type checking] - Cannot call A#m1(T2) with arguments [#X]
       @ line 8, column 5.
             (new A<T2, T2>()).m1(x.m2(y));
             ^
      
      1 error
      

      Expected behaviour

      Compile successfully.

      *Note*: If I change the expected type of parameter `x` in method `m1(T1 x)` to `m1(T2 x`), the program 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: