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

Type variable of function does not shadow the corresponding type variable of class

    XMLWordPrintableJSON

Details

    Description

      I have the following program

      class A<T> {
        <T> T foo(T t) { return t; }
      }
      
      
      class B {
      
        void bar(int x) {}
      
        void test() {
          int x = (new A<String>()).foo(1);
        }
      }
      

      Actual behaviour

      org.codehaus.groovy.control.MultipleCompilationErrorsException: startup failed:
      test.groovy: 11: [Static type checking] - Cannot find matching method A#foo(int). Please check if the declared type is correct and if the method exists.
       @ line 11, column 13.
             int x = (new A<String>()).foo(1);
                     ^
      
      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: