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

Paul King updated GROOVY-12097:
-------------------------------
    Description: 
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}

  was:
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}


> 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
>            Priority: Major
>
> 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}



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

Reply via email to