[
https://issues.apache.org/jira/browse/GROOVY-12613?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=18135680#comment-18135680
]
ASF GitHub Bot commented on GROOVY-12613:
-----------------------------------------
testlens-app[bot] commented on PR #3140:
URL: https://github.com/apache/groovy/pull/3140#issuecomment-6540449846
## ✅ All tests passed ✅
🏷️ Commit: b54a1164238f42198ddc397a55e6804b746b0442
▶️ Tests: 109593 executed
⚪️ Checks: 26/26 completed
---
_Learn more about TestLens at
[testlens.app/docs](https://testlens.app/docs/features/pr-comment/)._
> Compound assignment in a trait method evaluates its target twice when the
> target is not a trait field
> -----------------------------------------------------------------------------------------------------
>
> Key: GROOVY-12613
> URL: https://issues.apache.org/jira/browse/GROOVY-12613
> 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 {
> def m() { def l = [0, 0]; int i = 0; l[i++] += 1; [i, l] }
> }
> class C implements T {}
> assert new C().m() == [1, [1, 0]]
> {code}
> Actual: {{new C().m()}} returns {{[2, [1, 0]]}}. The index expression runs
> twice. The same method in a class returns {{[1, [1, 0]]}}. The receiver or
> subscript of any compound assignment in a trait method is evaluated twice,
> for example a map subscript key() is called twice. This happens with and
> without @CompileStatic / @TypeChecked.
> Expected: {{[1, [1, 0]]}}. A compound assignment evaluates its target once,
> as it does in a class.
> Cause: the trait transformation (NAryOperationRewriter) rewrites every
> compound assignment in trait code into a plain assignment (a = a op b). The
> rewrite is only needed when the target is a trait field, which becomes a
> field-helper getter/setter call.
> Seen in 4.0.33, 5.0.8 and 6.0.0.
> PR: https://github.com/apache/groovy/pull/3140
--
This message was sent by Atlassian Jira
(v10.3.26#10030026)