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

STC is unable to infer type parameter of parameterized method call

    XMLWordPrintableJSON

Details

    • Bug
    • Status: Closed
    • Major
    • Resolution: Fixed
    • None
    • 4.0.3
    • Static Type Checker
    • None

    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

            People

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

              Dates

                Created:
                Updated:
                Resolved: