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

Strange @CompileStatic check in Closure

    XMLWordPrintableJSON

Details

    Description

      This code compiles normal:

      @CompileStatic
      class B {
          public <T> T bar(Closure<Collection<Integer>> a) {
              return null
          }
      
          def use() {
             bar {
                  [1]
              }
          }
      }
      

      Switching return type cause error in code:

      import groovy.transform.CompileStatic
      
      @CompileStatic
      class B {
          public def bar(Closure<Collection<Integer>> a) {
              return null
          }
      
          def use() {
              bar { // Error:(21, 9) Groovyc: [Static type checking] - Cannot find matching method pack.B#bar(groovy.lang.Closure <java.util.List>). 
                  [1]
              }
          }
      }
      

      I believe first example should have error too. But probably after fixing in that way following code will be broken:

      def foo() {
              def nums = [1]
              def res = nums.collectMany { [it] }
          }
      

      Attachments

        Issue Links

          Activity

            People

              emilles Eric Milles
              Alexey Afanasiev Alexey Afanasiev
              Votes:
              0 Vote for this issue
              Watchers:
              4 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 - 40m
                  40m