natural / java2python

Simple but effective library to translate Java source code to Python.
GNU Lesser General Public License v2.1
564 stars 243 forks source link

wrong translation of x++ operator #46

Open yucer opened 8 years ago

yucer commented 8 years ago

Here is another one. I don't know if this comes from ANTLR, or is something that could be solved here.

The Java code:

if (condition):
    myArr[count++] = index;
    # .. more code here
    myArr[count++] = index;

is translated to:

__count_1 = count
count += 1
__count_2 = count
count += 1
if condition:
    myArr[__count_1] = index;
    # .. more code here
    myArr[__count_2] = index;

It should be translated to:

if condition:
    myArr[count] = index;
    count += 1
    # .. more code here
    myArr[count] = index;
    count += 1

Otherwise the result is not the same if the additional code between both assignments do change the count variable.