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

Incorrect inference of type argument of parameterized method call

    XMLWordPrintableJSON

Details

    Description

      Maybe related to GROOVY-10342

      I have the following groovy program

      class Foo<T> {
        Foo(T x) {}
      }
      
      
      class Main  {
      
        static <T> void bar() {
          new Foo<T>(baz());
        }
      
        static <Z> Z baz() {
          return null;
        }
      
      }
      

      Actual behaviour

      The compiler rejects the code with

      org.codehaus.groovy.control.MultipleCompilationErrorsException: startup failed:
      test.groovy: 9: [Static type checking] - Cannot call Foo#<init>(T) with arguments [#Z]
       @ line 9, column 5.
             new Foo<T>(baz());
             ^
      
      1 error
      

      Expected behaviour

      Compile successfully.

      Tested against https://github.com/apache/groovy/commit/5601ea14304b67e71586b0196e38f90fa1a46f5b.

      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: