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

STC is unable to infer type parameter of parameterized method call

Attach filesAttach ScreenshotVotersWatch issueWatchersCreate sub-taskLinkCloneUpdate Comment AuthorReplace String in CommentUpdate Comment VisibilityDelete Comments
    XMLWordPrintableJSON

Details

    Description

      I have the following program

      class A<T> {
        T f;
      }
      
      class Test {
        static <T> T m() { return null; }
      
        static <T extends Number> void test() {
          String x = m(); // works
      
          A<String> y = new A<>();
          y.f = m(); // works
      
          A<T> z = new A<T>();
          z.f = m(); // does not work
        }
      
      }
      

      Actual behaviour

      org.codehaus.groovy.control.MultipleCompilationErrorsException: startup failed:
      test.groovy: 15: [Static type checking] - Cannot assign value of type #T to variable of type T
       @ line 15, column 11.
             z.f = m();
                   ^
      
      1 error
      

      Expected behavior

      Compile successfully

      NOTE: Replacing `T extends Number` with `T` compiles code successfully.

      Tested against master.

      Attachments

        Issue Links

        Activity

          This comment will be Viewable by All Users Viewable by All Users
          Cancel

          People

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

            Dates

              Created:
              Updated:
              Resolved:

              Slack

                Issue deployment