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

Left shift on collection fails for list with CompileStatic

    XMLWordPrintableJSON

Details

    • Bug
    • Status: Closed
    • Major
    • Resolution: Fixed
    • 2.0.6
    • 2.1.1
    • Static compilation
    • None

    Description

      Don't think I've reported this before...

      This code works fine:

      @groovy.transform.CompileStatic
      def List<Integer> append( Closure<Integer> method ) {
        List<Integer> ret = []
        ret << method()
      }
      
      Closure<Integer> cl = { 2 }
      
      // prints '[2]'
      println append( cl )
      

      However, if you use a generic placeholder like so:

      @groovy.transform.CompileStatic
      def <T> List<T> append( Closure<T> method ) {
        List<T> ret = []
        ret << method()
      }
      
      Closure<Integer> cl = { 2 }
      
      println append( cl )
      

      You get:

      [Static type checking] - Cannot call 
        org.codehaus.groovy.runtime.DefaultGroovyMethods#leftShift(java.util.Collection <T>, java.lang.Object)
        with arguments [java.util.List <T>, java.lang.Object] 
      

      Shouldn't that be ok?

      Attachments

        Activity

          People

            melix Cédric Champeau
            tim_yates Tim Yates
            Votes:
            0 Vote for this issue
            Watchers:
            3 Start watching this issue

            Dates

              Created:
              Updated:
              Resolved: