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

Scott Murphy Heiberg updated GROOVY-12581:
------------------------------------------
    Description: 
{code:groovy}
@groovy.transform.CompileStatic
class C {
    List<String> log = [];
    { log << new StringBuilder('a').with { append('b'); toString() } }
}
new C() // IncompatibleClassChangeError: Class java.lang.StringBuilder does not 
implement the requested interface groovy.lang.GroovyObject
{code}

The type checker records when an implicit-this call in a closure goes to the 
delegate, and the static invocation writer then replaces the receiver with 
{{this.delegate}}, but keeps the call adapter chosen for a call on {{this}}. 
The instance initializer blocks of a {{@CompileStatic}} class are type checked 
but their calls get no method targets, so the call is made dynamically with 
{{ScriptBytecodeAdapter.invokeMethodOnCurrent}}, which takes a 
{{GroovyObject}}. {{with}}, {{tap}} and other delegating closures in such 
blocks fail with any delegate that is not a Groovy object. 4.0.33 returns 
{{[ab]}}.

PR: https://github.com/apache/groovy/pull/3107

  was:
{code:groovy}
@groovy.transform.CompileStatic
class C {
    List<String> log = [];
    { log << new StringBuilder('a').with { append('b'); toString() } }
}
new C() // IncompatibleClassChangeError: Class java.lang.StringBuilder does not 
implement the requested interface groovy.lang.GroovyObject
{code}

The type checker records when an implicit-this call in a closure goes to the 
delegate, and the static invocation writer then replaces the receiver with 
{{this.delegate}}, but keeps the call adapter chosen for a call on {{this}}. 
The instance initializer blocks of a {{@CompileStatic}} class are type checked 
but their calls get no method targets, so the call is made dynamically with 
{{ScriptBytecodeAdapter.invokeMethodOnCurrent}}, which takes a 
{{GroovyObject}}. {{with}}, {{tap}} and other delegating closures in such 
blocks fail with any delegate that is not a Groovy object. 4.0.33 returns 
{{[ab]}}.


> SC: a delegating closure in an instance initializer block fails for a 
> delegate that is not a Groovy object
> ----------------------------------------------------------------------------------------------------------
>
>                 Key: GROOVY-12581
>                 URL: https://issues.apache.org/jira/browse/GROOVY-12581
>             Project: Groovy
>          Issue Type: Bug
>          Components: Static compilation
>    Affects Versions: 5.0.8, 6.0.0
>            Reporter: Scott Murphy Heiberg
>            Priority: Major
>
> {code:groovy}
> @groovy.transform.CompileStatic
> class C {
>     List<String> log = [];
>     { log << new StringBuilder('a').with { append('b'); toString() } }
> }
> new C() // IncompatibleClassChangeError: Class java.lang.StringBuilder does 
> not implement the requested interface groovy.lang.GroovyObject
> {code}
> The type checker records when an implicit-this call in a closure goes to the 
> delegate, and the static invocation writer then replaces the receiver with 
> {{this.delegate}}, but keeps the call adapter chosen for a call on {{this}}. 
> The instance initializer blocks of a {{@CompileStatic}} class are type 
> checked but their calls get no method targets, so the call is made 
> dynamically with {{ScriptBytecodeAdapter.invokeMethodOnCurrent}}, which takes 
> a {{GroovyObject}}. {{with}}, {{tap}} and other delegating closures in such 
> blocks fail with any delegate that is not a Groovy object. 4.0.33 returns 
> {{[ab]}}.
> PR: https://github.com/apache/groovy/pull/3107



--
This message was sent by Atlassian Jira
(v10.3.26#10030026)

Reply via email to