You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@groovy.apache.org by "Eric Milles (Jira)" <ji...@apache.org> on 2022/02/22 18:45:00 UTC

[jira] [Updated] (GROOVY-9586) SC: calling trait method inside closure has incorrect receivers data

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

Eric Milles updated GROOVY-9586:
--------------------------------
    Summary: SC: calling trait method inside closure has incorrect receivers data  (was: CLONE - SC: calling trait method inside closure has incorrect receivers data)

> SC: calling trait method inside closure has incorrect receivers data
> --------------------------------------------------------------------
>
>                 Key: GROOVY-9586
>                 URL: https://issues.apache.org/jira/browse/GROOVY-9586
>             Project: Groovy
>          Issue Type: Bug
>          Components: Static compilation
>            Reporter: Eric Milles
>            Assignee: Eric Milles
>            Priority: Major
>             Fix For: 4.0.0-alpha-1, 3.0.5
>
>
> Consider the following
> {code:groovy}
> class C {
>   def m(@DelegatesTo(strategy=Closure.OWNER_ONLY, type='Void') Closure<?> block) {
>     block.setResolveStrategy(Closure.OWNER_ONLY)
>     block.setDelegate(null)
>     return block.call()
>   }
>   def x() { 'C' }
>   }
> trait T {
>   def test() {
>     new C().m { -> x() } // "x" must come from owner
>   }
>   def x() { 'T' }
> }
> class U implements T {
> }
> assert new U().test() == 'T'
> {code}
> Under static compilation, the implicit receiver metadata that is collected by StaticTypeCheckingVisitor is incorrect because the receiver T is only added for T$Trait$Helper under the delegate path.  When using OWNER_ONLY, the trait is not checked and no direct method call target is set for "x()".  So it falls back to dynamic behavior.



--
This message was sent by Atlassian Jira
(v8.20.1#820001)