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

Unable to compile: Expected type for closure parameter

    XMLWordPrintableJSON

Details

    Description

      This code is unable to compile, throwing the exception:

      Main.groovy: 15: 22: [Static type checking] - Expected type java.util.List<T> for closure parameter: list
       @ line 22, column 17.
                         List<String> list ->
                         ^ 
      
      Main.groovy: 17: [Static type checking] - Expected type java.lang.Object for closure parameter: tm
       @ line 17, column 21.
                             TestModel tm ->
                             ^
      
      Main.groovy: 18: [Static type checking] - No such property: id for class: java.lang.Object
       @ line 18, column 33.
                                 println(tm.id)
                                         ^

      Code:

      @CompileStatic
      class Main {
          static void main(String[] args) {
              TestTable table = new TestTable()
              table.getAll({
                  List<TestModel> list ->
                      list.each {
                          TestModel tm ->
                              println(tm.id)
                      }
              })
          }
      }

      This is a simplified version of my code which worked fine in 3.0.11, it failed first on 3.0.12 including 4.x. 

      I have prepared a git project with the minimum code at:

      https://gitlab.com/intellisrc/groovy-compile-error2

      In build.gradle you can change between 3.0.11 and 4.0.12 versions

       

      Attachments

        Issue Links

          Activity

            People

              emilles Eric Milles
              lepe A. Lepe
              Votes:
              0 Vote for this issue
              Watchers:
              2 Start watching this issue

              Dates

                Created:
                Updated:
                Resolved: