[PATCH] Fix java/13733

Jeff Sturm jsturm@one-point.com
Thu Jan 22 00:09:00 GMT 2004

Gcj currently compiles incorrect java code such as:

  String a;
  Object b;
  String c = "";

  a = (b = c);

whereas other java compilers (javac, jikes) rightly complain.

I traced it to this odd statement in patch_assignment:

   lhs_type = promote_type (rhs_type);

JLS 15.26 says "The type of the assignment expression is the type of the
variable" (where "variable" is the LHS of the assignment).  So the above
is clearly wrong, though it has existed in patch_assignment since
revision 1.1, when the Java FE was first merged into the EGCS repository!
I have no way to tell why this was done.  It may have been simply a typo
all along, since promoting the RHS by itself would make sense.

(This bug may have gone unnoticed forever were it not for the strict type
checking of the gimplifier in tree-ssa, which currently prevents Eclipse
from compiling on the branch.  There doesn't even seem to be a Jacks test
for this language requirement.  This patch should also fix the ICE on
tree-ssa, which was my real motivation to work on it.)

Tested on i686-pc-linux-gnu, no regressions in libjava, mauve or jacks.
OK for mainline?


2004-01-21  Jeff Sturm  <jsturm@one-point.com>

	PR java/13733
	* parse.y (patch_assignment): Don't modify lhs_type for
	reference assignments.

Index: parse.y
RCS file: /cvs/gcc/gcc/gcc/java/parse.y,v
retrieving revision 1.464
diff -u -r1.464 parse.y
--- parse.y	9 Jan 2004 17:08:44 -0000	1.464
+++ parse.y	21 Jan 2004 02:13:55 -0000
@@ -12652,8 +12652,8 @@
   new_rhs = try_builtin_assignconv (wfl_op1, lhs_type, rhs);

   /* 5.2 If it failed, try a reference conversion */
-  if (!new_rhs && (new_rhs = try_reference_assignconv (lhs_type, rhs)))
-    lhs_type = promote_type (rhs_type);
+  if (!new_rhs)
+    new_rhs = try_reference_assignconv (lhs_type, rhs);

   /* 15.25.2 If we have a compound assignment, convert RHS into the
      type of the LHS */

More information about the Gcc-patches mailing list