eclipse-xtext / eclipse-xtext/xtext

Method call argument evaluation order incorrect

Open
#2,290 4 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

bug confirmed
Dominant language
Java
Stars
831
Forks
330
Avg merge
3d 7h
Merged PRs (30d)
12

Description

Arguments don't evaluate from left to right in some scenarios.
Example:

class Order {
    static val array = newIntArrayOfSize(1)
    static var index = 0

    def static void main(String[] args) {
        array.set(index, index++)
    }
}

Compiles to:

@SuppressWarnings("all")
public class Order {
  private final static int[] array = new int[1];
  
  private static int index = 0;
  
  public static void main(final String[] args) {
    int _plusPlus = Order.index++;
    Order.array[Order.index] = _plusPlus;
  }
}

As a result, behaves incorrectly:

Exception in thread "main" java.lang.ArrayIndexOutOfBoundsException: 1
	at Order.main(Order.java:11)

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start by reproducing the issue from the Order example and compare the generated Java with the intended left-to-right argument evaluation. The issue does not name source files or tests; done means the generated code evaluates arguments left to right and the example no longer throws ArrayIndexOutOfBoundsException.

Written by the indexing model from the issue text.

Assessment

Tech stack
java
Domain
compilers
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
25/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.