[ 
https://issues.apache.org/jira/browse/GROOVY-12097?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel
 ]

Paul King resolved GROOVY-12097.
--------------------------------
    Fix Version/s: 6.0.0-alpha-2
       Resolution: Fixed

> a[index] = expr evaluates RHS before index, breaking left-to-right evaluation 
> order
> -----------------------------------------------------------------------------------
>
>                 Key: GROOVY-12097
>                 URL: https://issues.apache.org/jira/browse/GROOVY-12097
>             Project: Groovy
>          Issue Type: Bug
>            Reporter: Paul King
>            Assignee: Paul King
>            Priority: Major
>              Labels: breaking
>             Fix For: 6.0.0-alpha-2
>
>
> bq. AI read: The intent of GROOVY-2556 was to stop double-evaluating the 
> object/index in compound subscript assignments (x[i] += v) — the first hunk 
> of that commit. Reordering plain = was an unintended side effect of the 
> "related problems" cleanup.
> GROOVY-2556 fixed some cases involved array expressions with side effects but 
> also changed the index value on the LHS of an assignment. The following Java 
> and Groovy program gave the same result prior to the change (Groovy 1.5.2ish) 
> but the behavior below since then:
> {code:groovy}
> public class C {
>   public static void main(String[] args) {
>     int[] a = new int[]{-1, -1, -1, -1};
>     int x = 0;
>     int y = 3;
>     a[x] = x++;
>     a[y] = --y;
>     System.out.println("[" + a[0] + "," + a[1] + "," + a[2] + "," + a[3] + 
> "]");
>     // Groovy: [-1,0,2,-1], Java: [0,-1,-1,2]
>   }
> }
> {code}
> JLS Links for comparison with Java (Java SE 21 JLS):
> * §15.7 (left-to-right): 
> https://docs.oracle.com/javase/specs/jls/se21/html/jls-15.html#jls-15.7
> * §15.26.1 (the array-assignment order): 
> https://docs.oracle.com/javase/specs/jls/se21/html/jls-15.html#jls-15.26.1



--
This message was sent by Atlassian Jira
(v8.20.10#820010)

Reply via email to