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

Wrong type argument is inferred on combining use-site variance and diamond operator

    XMLWordPrintableJSON

Details

    Description

      This bug may be related to GROOVY-10337.

      I have the following program

      class A<T> {
        A(T f, B<T, ? extends T> x){  } 
      }
      
      class B<T1, T2> {}
      
      class Test {
        void test() {
          B<Integer, ? extends Integer> x = null;
          A<Integer> y = new A<>(1, x);
        }
      }
      

      Actual behaviour

      org.codehaus.groovy.control.MultipleCompilationErrorsException: startup failed:
      test.groovy: 10: [Static type checking] - Incompatible generic argument types. Cannot assign A<? extends java.lang.Object> to: A<java.lang.Integer>
       @ line 10, column 20.
             A<Integer> y = new A<>(1, x);
                            ^
      
      1 error
      

      Expected behaviour

      Compile successfully

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

      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: