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

static type checker cannot infer type of for loop variable from map

    XMLWordPrintableJSON

Details

    Description

      The following code fails type checking as the inferred type of the entry loop variable is Object.

      @groovy.transform.CompileStatic
      class Looper {
          static void main(String... args) {
              Map<String, Integer> map = [foo: 123, bar: 456]
              for (entry in map) {
                  println entry.key.reverse()
                  println entry.value * 2
              }
          }
      }
      

      If I change it to for (entry in map.entrySet()) it works fine.

      Attachments

        Issue Links

          Activity

            People

              melix Cédric Champeau
              robfletcher Rob Fletcher
              Votes:
              0 Vote for this issue
              Watchers:
              2 Start watching this issue

              Dates

                Created:
                Updated:
                Resolved: