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

The diamond operator does not work when passing a value whose type is a type variable

    XMLWordPrintableJSON

Details

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

    Description

      I have the following program

       

      class A<T> {
        void foo() {
          T z = null;
          T x = new B<>(z).f // does not work
      
          String y = ""
          String k = new B<>(y).f // works
        }
        
      }
      class B<X> {
        X f;
        B(X f) {
          this.f = f;
        }
      }
      

      Actual behaviour

      org.codehaus.groovy.control.MultipleCompilationErrorsException: startup failed:
      test.groovy: 4: [Static type checking] - Cannot assign value of type X to variable of type T
       @ line 4, column 11.
             T x = new B<>(z).f // does not work
                   ^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:
            1 Start watching this issue

            Dates

              Created:
              Updated:
              Resolved: