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

FirstParam.FirstGenericType don't works whe the method returns generic type

    XMLWordPrintableJSON

Details

    • Bug
    • Status: Closed
    • Major
    • Resolution: Fixed
    • 2.2.1, 2.3.0-rc-1
    • 2.3.0-rc-2
    • Compiler
    • None
    • Groovy Version: 2.3.0-rc-1 JVM: 1.7.0_10 Vendor: Oracle Corporation OS: Mac OS X 10.9.2

    Description

      Following code fails. The method which using FirstParam.FirstGeneics and returns generic type (where List<T>), it have no effect for closure parameter inference. FirstParam.ToString also didn't works.

      fails:

          // NG. FirstParams.FirstGenericType looks don't works.
          static <T> List<T> callee01(List<T>self, @ClosureParams(FirstParam.FirstGenericType) Closure c) {
              self.each {
                  c.call(it)
              }
              return self
          }
          // NG
          @TypeChecked
          void caller01() {
              callee01(["a","b","c"]) { a ->
                  println(a.toUpperCase()) // [Static type checking] - Cannot find matching method java.lang.Object#toUpperCase(). Please check if the declared type is right and if the method exists.
              }
          }
      

      if the return type is void, it works.

          // OK
          static <T> void callee02(List<T>self, @ClosureParams(FirstParam.FirstGenericType) Closure c) {
              self.each {
                  c.call(it)
              }
          }
          @TypeChecked
          void caller02() {
              callee02(["a","b","c"]) { a ->
                  println(a.toUpperCase())
              }
          }
          
      

      and if the return type is monomorphic type, its also ok(following case, it's String)

          static <T> String callee03(List<T>self, @ClosureParams(FirstParam.FirstGenericType) Closure c) {
              self.each {
                  c.call(it)
              }
              return "foo"
          }
      
          @TypeChecked
          void caller03() {
              callee03(["a","b","c"]) { a ->
                  println(a.toUpperCase())
              }
          }
      

      Attachments

        1. FirstParamTest.groovy
          1 kB
          UEHARA Junji

        Activity

          People

            melix Cédric Champeau
            uehaj UEHARA Junji
            Votes:
            0 Vote for this issue
            Watchers:
            1 Start watching this issue

            Dates

              Created:
              Updated:
              Resolved: