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

Eric Milles commented on GROOVY-7304:
-------------------------------------

Similar to GROOVY-8707, the prefix expression "++i" performs a standard visit 
for the LHS, which results in a ScriptBytecodeAdapter#setProperty (via 
{{visitAttributeOrProperty}} -> 
{{controller.getCallSiteWriter().fallbackAttributeOrPropertySite(...)}}).

The special handling in StaticTypesBinaryExpressionMultiTypeDispatcher that 
converts an expression into a setter call is not easily adaptable to a 
situation where the RHS expression has already been visited and is on the 
operand stack.  If it was, it could be applied within 
BinaryExpressionHelper#execMethodAndStoreForSubscriptOperator.

> Cannot mutate private field from within an AIC or a closure
> -----------------------------------------------------------
>
>                 Key: GROOVY-7304
>                 URL: https://issues.apache.org/jira/browse/GROOVY-7304
>             Project: Groovy
>          Issue Type: Bug
>          Components: Static compilation
>            Reporter: Jochen Theodorou
>            Priority: Major
>
> {code:Java}
> class Foo {
>     private int i = 1
>     @groovy.transform.CompileStatic
>     def m() { new String().with {++i}}
> }
> assert new Foo().m() == 2
> class Bar extends Foo {}
> assert new Bar().m() == 2{code}
> The static compiler is unable to generate code which handles the mutation of 
> a private field like in the example above.



--
This message was sent by Atlassian Jira
(v8.3.4#803005)

Reply via email to