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

@CompileStatic calls DefaultGroovyMethods.iterator with Iterator value in for loop

Attach filesAttach ScreenshotAdd voteVotersWatch issueWatchersCreate sub-taskLinkCloneUpdate Comment AuthorReplace String in CommentUpdate Comment VisibilityDelete Comments
    XMLWordPrintableJSON

    Details

    • Type: Improvement
    • Status: Open
    • Priority: Major
    • Resolution: Unresolved
    • Affects Version/s: 2.4.12
    • Fix Version/s: None
    • Labels:
      None

      Description

      @groovy.transform.CompileStatic
      class IteratorTest {
        static main(args) {
          final a = [1, 2, 3, 4, 5]
          for (x in a.iterator()) println x
        }
      }
      

      bytecode (important part commented out):

      38 aastore
      39 invokestatic #39 <org/codehaus/groovy/runtime/ScriptBytecodeAdapter/createList([Ljava/lang/Object;)Ljava/util/List;>
      42 astore_1
      43 aload_1
      44 pop
      45 aconst_null
      46 astore_2
      47 aload_1
      48 invokeinterface #45 <java/util/List/iterator()Ljava/util/Iterator;> count 1
      /*53 invokestatic #50 <org/codehaus/groovy/runtime/DefaultGroovyMethods/iterator(Ljava/lang/Object;)Ljava/util/Iterator;>*/
      56 astore_3
      57 aload_3
      58 invokeinterface #56 <java/util/Iterator/hasNext()Z> count 1
      63 ifeq 84 (+21)
      66 aload_3
      67 invokeinterface #60 <java/util/Iterator/next()Ljava/lang/Object;> count 1
      72 astore_2
      73 ldc #2 <IteratorTest>
      75 aload_2
      76 invokestatic #64 <org/codehaus/groovy/runtime/DefaultGroovyMethods/println(Ljava/lang/Object;Ljava/lang/Object;)V>
      79 aconst_null
      80 pop
      81 goto 57 (-24)
      84 return
      

      (sidenote: aren't 43-46 useless as well?)

        Attachments

          Activity

            People

            • Assignee:
              Unassigned
              Reporter:
              deathlord death lord

              Dates

              • Created:
                Updated:

                Issue deployment