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

Class-Level Closure Definition With Generics Fails TypeChecked

    XMLWordPrintableJSON

Details

    • Bug
    • Status: Closed
    • Major
    • Resolution: Fixed
    • 2.5.5, 3.0.0, 3.0.3
    • 4.0.0-alpha-1, 3.0.6, 2.5.16
    • None
    • None

    Description

       

       

      import groovy.transform.TypeChecked
      
      @TypeChecked
      abstract class A<T extends List>{
          Collection<T> testQueue
          Closure c = {
              testQueue.each{T item->
                  println item
              }
          }
          //def foo() {
          //    testQueue.each{T item->
          //        println item
          //    }
          //}
      }
      new A<LinkedList>(){}
      

      Put this in filename.groovy and call "groovy filename.groovy" and I get

       

      org.codehaus.groovy.control.MultipleCompilationErrorsException: startup failed:
      /home/ianl/closureGeneric.groovy: 9: Expected parameter of type java.lang.Object but got T
       @ line 7, column 24.
                 testQueue.each{T item->
                                ^
      1 error

      Yet, uncomment the method foo() and there's no error there. or put the closure definition into the method and there's no error.

      Attachments

        Activity

          People

            emilles Eric Milles
            tofor Ian
            Votes:
            0 Vote for this issue
            Watchers:
            1 Start watching this issue

            Dates

              Created:
              Updated:
              Resolved:

              Time Tracking

                Estimated:
                Original Estimate - Not Specified
                Not Specified
                Remaining:
                Remaining Estimate - 0h
                0h
                Logged:
                Time Spent - 20m
                20m