[
https://issues.apache.org/jira/browse/GROOVY-12638?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=18136035#comment-18136035
]
ASF GitHub Bot commented on GROOVY-12638:
-----------------------------------------
testlens-app[bot] commented on PR #3161:
URL: https://github.com/apache/groovy/pull/3161#issuecomment-6555834196
## 🚨 All tests passed but jobs failed 🚨
### Failed Jobs without Test Failures
❌ [Build and test / lts \(17,
macos-latest\)](https://github.com/apache/groovy/actions/runs/41286820091/job/124789694102?pr=3161)
🏷️ Commit: 68c725b1d49f1482519040a6999090f299455940
▶️ Tests: 115546 executed
⚪️ Checks: 26/26 completed
### Rerun Controls
Click the checkbox to trigger a rerun:
- [ ] **Rerun jobs**
---
_Learn more about TestLens at
[testlens.app/docs](https://testlens.app/docs/features/pr-comment/)._
> Elvis assignment (?=) to a trait field does not assign the field
> ----------------------------------------------------------------
>
> Key: GROOVY-12638
> URL: https://issues.apache.org/jira/browse/GROOVY-12638
> Project: Groovy
> Issue Type: Bug
> Affects Versions: 4.0.33, 5.1.3, 6.0.0
> Reporter: Paul King
> Priority: Major
>
> {code:groovy}
> trait T {
> Integer n
> def m() { n ?= 5; n }
> }
> class C implements T {}
> println new C().m()
> {code}
> Actual: prints {{null}} in dynamic and @TypeChecked code. With
> @CompileStatic, compilation fails with {{General error during instruction
> selection: Internal compiler error}}. The same happens inside a closure in
> trait code.
> Expected: 5, as for the same field and method in an ordinary class, or for a
> local variable in trait code.
> Cause: NAryOperationRewriter rewrites the compound assignments of trait
> fields using TokenUtil.removeAssignment, which has no entry for ELVIS_EQUAL,
> so {{n ?= 5}} is not rewritten. TraitReceiverTransformer handles only plain
> assignment ({{=}}) to a trait field specially, so the field on the left of
> {{?=}} is transformed as a read (a call of the field helper's getter), and
> the value is never written to the field. Rewriting {{x ?= y}} for a trait
> field as {{x = x ?: y}} (an ElvisOperatorExpression, since there is no binary
> elvis operator to pass back) would give the expected result.
--
This message was sent by Atlassian Jira
(v10.3.26#10030026)