Name: laC46010 Date: 04/10/97
Java compiler (JDK1.0.2 - JDK1.1.2) incorrectly reports syntax error
for valid statements like i=(i)++; and i=(i)--;
JLS (15.14, p.347) says:
"In Java, the result of the -- operator must be numeric, and all type
names involved in casts on numeric values are known keywords. Thus, if
p is a keyword naming a primitive type, then (p)-- can make sense only
as a cast of a prefix increment expression, and there had better be an
operand such as q following the --. However, if p is not a keyword
naming a primitive type, then (p)++ can make sense only as a postfix
increment of p. Similar remarks apply to the -- operator."
This obviously allows considered constructions.
See also JCK tests:
lang/EXPR/expr201/expr20201/expr20201
lang/EXPR/expr203/expr20305/expr20305
These test were considered as negative but in fact they
should be positive.
See an example and compiler output below:
--------------------------------------
class expr20201
{
void run()
{
int i = 0;
i=(i)++;
i=(i)--;
i=++(i);
i=--(i);
}
}
--------------------------------------
/home/leo/java/bug/expr20201_210 /export/ld13/java/dest/jdk1.1.2/solaris/bin/java -version
java version "1.1.2"
/home/leo/java/bug/expr20201_211 /export/ld13/java/dest/jdk1.1.2/solaris/bin/javac expr20201.java
expr20201.java:6: Missing term.
i=(i)++;
^
expr20201.java:7: Missing term.
i=(i)--;
^
2 errors
======================================================================