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

Nested diamond operators do not work correctly although the expected type argument is known

    XMLWordPrintableJSON

Details

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

    Description

      I have the following program:

      class C<T> {
        C(D<T> x) {}
      }
      
      class D<T> {}
      
      
      class Test {
        void test() {
          C<Float> x = new C<>(new D<>()); // type variables are instantiated with type Float because of the left-hand side.
        }
      
      }
      

      Actual behavior

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

      Expected behavior

      Compile successfully

      Tested against master (commit: ee12bb52381e8f0583c61fc25d43de1f55b80a87)

      Attachments

        Activity

          People

            emilles Eric Milles
            theosot Thodoris Sotiropoulos
            Votes:
            1 Vote for this issue
            Watchers:
            3 Start watching this issue

            Dates

              Created:
              Updated:
              Resolved: