[
https://issues.apache.org/jira/browse/GROOVY-12611?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=18140527#comment-18140527
]
ASF GitHub Bot commented on GROOVY-12611:
-----------------------------------------
codeconsole commented on PR #3138:
URL: https://github.com/apache/groovy/pull/3138#issuecomment-6717051853
@daniellansun I can't re-run jobs on apache/groovy, so I merged current
master (492ae79db4) to get a fresh run. `native-check` failed in
`graalvm/setup-graalvm`, which master has since bumped to 1.6.8. No code
changes; `TraitASTTransformationTest` passes locally on the merge.
> A private or static trait method called from a closure ignores the closure's
> delegate
> -------------------------------------------------------------------------------------
>
> Key: GROOVY-12611
> URL: https://issues.apache.org/jira/browse/GROOVY-12611
> Project: Groovy
> Issue Type: Bug
> Affects Versions: 4.0.33, 5.0.8, 6.0.0
> Reporter: Scott Murphy Heiberg
> Priority: Major
>
> {code:groovy}
> trait T {
> private int size() { 1 } // or: static int size() { 1 }
> def m() { [5, 6].with { size() } }
> }
> class C implements T {}
> assert new C().m() == 2
> {code}
> Actual: 1, in dynamic, @TypeChecked and @CompileStatic code. The same happens
> for a static trait method called from a static trait method.
> Expected: 2, as for the same code in a class. The delegate's method is used
> when the resolve strategy tries the delegate first and the delegate has the
> method. Otherwise the trait method is called. A public instance trait method
> already behaves this way.
> Cause: TraitReceiverTransformer rewrites an implicit-this call to a private
> or static trait method inside a closure into a direct call on the trait
> helper class, so the closure's delegate is never consulted.
> Seen in 4.0.33, 5.0.8 and 6.0.0 (4.0.33 is right for public static methods).
> PR: https://github.com/apache/groovy/pull/3138
--
This message was sent by Atlassian Jira
(v10.3.26#10030026)