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

Left shift on collection fails for list with CompileStatic

    XMLWordPrintableJSON

    Details

    • Type: Bug
    • Status: Closed
    • Priority: Major
    • Resolution: Fixed
    • Affects Version/s: 2.0.6
    • Fix Version/s: 2.1.1
    • Component/s: Static compilation
    • Labels:
      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

            • Assignee:
              melix C├ędric Champeau
              Reporter:
              tim_yates Tim Yates
            • Votes:
              0 Vote for this issue
              Watchers:
              3 Start watching this issue

              Dates

              • Created:
                Updated:
                Resolved: