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

Type variable inference does not work properly in nested diamond operators

    XMLWordPrintableJSON

Details

    Description

      I have the following program

      class A<T> {
        T f;
        A(T f) {
          this.f = f;
        }
      }
      
      class B<T> {
        A<T> f;
        B(A<T> f) {
          this.f = f;
        }
      }
      
      class Test {
        void test() {
          def x = new  B<>(new A<>((long) 1)).f;
          A<Long> y = x;
        }
        
      }
      

      Actual behaviour

      org.codehaus.groovy.control.MultipleCompilationErrorsException: startup failed:
      test.groovy: 18: [Static type checking] - Incompatible generic argument types. Cannot assign A<java.lang.Object> to: A<java.lang.Long>
       @ line 18, column 17.
             A<Long> y = x;
                         ^
      
      1 error
      

      Expected behaviour

      Compile successfully

      Tested against master

      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: