[ 
https://issues.apache.org/jira/browse/GROOVY-12615?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=18135689#comment-18135689
 ] 

ASF GitHub Bot commented on GROOVY-12615:
-----------------------------------------

testlens-app[bot] commented on PR #3141:
URL: https://github.com/apache/groovy/pull/3141#issuecomment-6540575879

   ## ✅ All tests passed ✅
   
   🏷️ Commit: cb61c63b4e680f94eb63d972400256287738c4a8
   ▶️ Tests:  118562 executed
   ⚪️ Checks: 26/26 completed
   
   ---
   _Learn more about TestLens at 
[testlens.app/docs](https://testlens.app/docs/features/pr-comment/)._
   




> Compound assignment to a trait field nested in the right operand of another 
> compound assignment fails at run time
> -----------------------------------------------------------------------------------------------------------------
>
>                 Key: GROOVY-12615
>                 URL: https://issues.apache.org/jira/browse/GROOVY-12615
>             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 { int a = 1, b = 1; def m() { a += (b += 1); [a, b] } }
> class C implements T {}
> assert new C().m() == [3, 2]
> {code}
> Actual: dynamic and type-checked code throws {{java.lang.ClassCastException: 
> Cannot cast java.lang.Integer to T$Trait$FieldHelper}}; with @CompileStatic 
> it throws {{GroovyCastException: Cannot cast object '2' with class 
> 'java.lang.Integer' to class 'T'}}. With static trait fields it throws a 
> VerifyError (dynamic) or fails to compile (@CompileStatic). A postfix update 
> in the same position, {{a += (b++)}}, compiles and silently loses the 
> increment, although postfix updates of trait fields are a compile error 
> everywhere else.
> Expected: [3, 2], and a postfix update there rejected with "Postfix 
> expressions on trait fields/properties are not supported in traits."
> Cause: NAryOperationRewriter rewrites x op= y into x = x op y but reuses the 
> right operand without transforming it, so a nested compound assignment to a 
> trait field stays a compound assignment applied to the field helper call, and 
> a nested postfix update is never checked.
> Seen in 4.0.33, 5.0.8 and 6.0.0.
> PR: https://github.com/apache/groovy/pull/3141



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

Reply via email to