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

Eric Milles resolved GROOVY-11872.
----------------------------------
    Fix Version/s: 5.0.5
       Resolution: Fixed

https://github.com/apache/groovy/commit/c136326a104f8c0488ecca94521707b21d702637

> SC: compile static method and default parameter values
> ------------------------------------------------------
>
>                 Key: GROOVY-11872
>                 URL: https://issues.apache.org/jira/browse/GROOVY-11872
>             Project: Groovy
>          Issue Type: Bug
>          Components: Static compilation
>    Affects Versions: 5.0.4
>            Reporter: Eric Milles
>            Assignee: Eric Milles
>            Priority: Major
>             Fix For: 5.0.5
>
>
> Consider the following:
> {code:groovy}
> class Foo {
>   @groovy.transform.CompileStatic
>   void bar(List list = baz()) {
>     for (item in list) {
>       println item
>     }
>   }
>   List baz() {
>     ['fizz','buzz']
>   }
> }
> new Foo().bar()
> {code}
> The generated method {{bar()}} gets the {{CompieStatic}} annotation, but when 
> classgen comes around, the direct method target to {{baz()}} is instead 
> written as an invokedynamic instruction.
> Actual bytecode:
> {code}
>   // Method descriptor #15 ()V
>   // Stack: 2, Locals: 1
>   @groovy.transform.Generated
>   public void bar();
>      0  aload_0 [this]
>      1  aload_0 [this]
>      2  invokedynamic 0 invoke(Foo) : java.lang.Object [79]
>      7  checkcast java.util.List [31]
>     10  invokevirtual Foo.bar(java.util.List) : void [81]
>     13  return
> {code}
> Expect bytecode:
> {code}
>   // Method descriptor #15 ()V
>   // Stack: 2, Locals: 1
>   @groovy.transform.Generated
>   public void bar();
>      0  aload_0 [this]
>      1  aload 0 [this]
>      3  invokevirtual Foo.baz() : java.util.List [68]
>      6  checkcast java.util.List [31]
>      9  invokevirtual Foo.bar(java.util.List) : void [70]
>     12  return
> {code}



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

Reply via email to