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

Fail to infer the type argument when using nested diamond operator

    XMLWordPrintableJSON

Details

    • Bug
    • Status: Closed
    • Major
    • Resolution: Fixed
    • None
    • 4.0.5, 3.0.20
    • Static Type Checker
    • None

    Description

      I have the following program

      class A<T> {
        A(T x, B<T> y) {}
      }
      
      class B<X> {}
      
      
      class Test {
        void test() {
          new A<>("fda", new B<>())
        }
      }
      

      Actual behavior

      org.codehaus.groovy.control.MultipleCompilationErrorsException: startup failed:
      test.groovy: 10: [Static type checking] - Cannot call A#<init>(java.lang.Object, B<java.lang.Object>) with arguments [java.lang.String, B<T>]
       @ line 10, column 5.
             new A<>("fda", new B<>())
             ^
      
      1 error
      

      Expected behavior

      Compile successfully.

      Tested against master (commit: 63bcab1bf13fb3811626fb1727c22e86528feb7f)

      *Notes:*

      • this bug occurs when the type parameters of class A and B involve different names
      • this bug is not triggered is groovy 4.0.2. It is introduced in groovy 4.0.3.

      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: