[ 
https://issues.apache.org/jira/browse/GROOVY-8487?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel
 ]

Eric Milles updated GROOVY-8487:
--------------------------------
    Issue Type: Bug  (was: Improvement)

> @CompileStatic calls DefaultGroovyMethods.iterator with Iterator value in for 
> loop
> ----------------------------------------------------------------------------------
>
>                 Key: GROOVY-8487
>                 URL: https://issues.apache.org/jira/browse/GROOVY-8487
>             Project: Groovy
>          Issue Type: Bug
>          Components: bytecode, Static compilation
>    Affects Versions: 2.4.12
>            Reporter: death lord
>            Assignee: Eric Milles
>            Priority: Major
>
> {code:java}
> @groovy.transform.CompileStatic
> class IteratorTest {
>   static main(args) {
>     final a = [1, 2, 3, 4, 5]
>     for (x in a.iterator()) println x
>   }
> }
> {code}
> bytecode (important part commented out):
> {code:java}
> 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
> {code}
> (sidenote: aren't 43-46 useless as well?)



--
This message was sent by Atlassian Jira
(v8.20.10#820010)

Reply via email to