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

STC fails to infer the correct type for type variable in the presence of the diamond operator and bounded polymorphism

    XMLWordPrintableJSON

Details

    Description

      This issue may be related to GROOVY-10343.

      I have the following program

      class A<Z, P extends Z> {
        Z f;
        A(Z f) {}
      }
      
      class B<Z extends Number> {
        Z f;
      
        void test() {
          f = new A<>((Z) null).f;
        }
      }
      

      Actual behaviour

      org.codehaus.groovy.control.MultipleCompilationErrorsException: startup failed:
      test.groovy: 10: [Static type checking] - Cannot assign value of type java.lang.Object to variable of type Z
       @ line 10, column 9.
             f = new A<>((Z) null).f;
                 ^
      
      1 error
      

      Expected behaviour

      Compile successfully

      NOTE: Replacing `Z extends Number` with `Z` leads to a successful compilation.

      Tested against master (https://github.com/apache/groovy/commit/cf2f77fb033a10d36c4db3a7ff07a2b04631afcf)

      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: