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

STC fails to substitute type variable when using the diamond operator and calling a closure

    XMLWordPrintableJSON

Details

    Description

      I have the following program

      class A<X> {
        X x;
        A(X x) {
          this.x = x
        }
      }
      
      
      class Test<T> {
      
        void foo() {
          def closure = { T p -> "" }
          T y = null
          bar(new A<>(y).x) // works
          closure(new A<>(y).x) // fails
        }
      
        void bar(T x) {} 
      }
      

      Actual behavior

      org.codehaus.groovy.control.MultipleCompilationErrorsException: startup failed:
      test.groovy: 15: [Static type checking] - Cannot call closure that accepts [T] with [X]
       @ line 15, column 12.
             closure(new A<>(y).x) // fails
                    ^
      
      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: