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

STC: support for-each or for-in loop for implicitly-Iterable type

    XMLWordPrintableJSON

Details

    • Improvement
    • Status: Closed
    • Minor
    • Resolution: Fixed
    • None
    • 5.0.0-alpha-11
    • Static Type Checker
    • None

    Description

      Consider the following:

      class C { // implicitly Iterable<String>
        Iterator<String> iterator() {} // sometimes supplied via DGM
      }
      
      @TypeChecked
      void test(C c) {
        for (string in c) {
          string.toUpperCase()
        }
      }
      

      If "@TypeChecked" is removed, this works. STC cannot determine the loop element type – see StaticTypeCheckingVisitor#inferLoopElementType and compare with inferComponentType which runs for spread.

      GROOVY-10476 describes the use case in more detail.

      Attachments

        Issue Links

          Activity

            People

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

              Dates

                Created:
                Updated:
                Resolved: