This is the mail archive of the java-patches@gcc.gnu.org mailing list for the Java project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]

[PATCH] Java: fix to a reported problem.



Tom reported a problem during a Classpath merge:

  http://gcc.gnu.org/ml/java/2001-09/msg00181.html

These patches fix the problem and add a test case to libjava's
testsuite. I'm checking these in.

./A

2001-09-26  Alexandre Petit-Bianco  <apbianco@redhat.com>

	* parse.y (check_final_variable_indirect_assignment): For
	COMPOUND_EXPR, return only if finals were found initialized
	properly, if not, keep on checking.
	(check_final_variable_global_assignment_flag): New local
	error_found, set when appropriate and used to decide whether to
	report uninitialized finals. Fixed typo in comment.

Index: parse.y
===================================================================
RCS file: /cvs/gcc/gcc/gcc/java/parse.y,v
retrieving revision 1.314
diff -u -p -r1.314 parse.y
--- parse.y	2001/09/22 05:03:35	1.314
+++ parse.y	2001/09/27 18:49:50
@@ -12638,7 +12638,7 @@ check_final_variable_indirect_assignment
       return check_final_variable_indirect_assignment (EXPR_WFL_NODE (stmt));
     case COMPOUND_EXPR:
       res = check_final_variable_indirect_assignment (TREE_OPERAND (stmt, 0));
-      if (res)
+      if (res > 0)
 	return res;
       return check_final_variable_indirect_assignment (TREE_OPERAND (stmt, 1));
     case SAVE_EXPR:
@@ -12679,6 +12679,7 @@ check_final_variable_global_assignment_f
 {
   tree field, mdecl;
   int nnctor = 0;
+  int error_found = 0;
 
   /* We go through all natural ctors and see whether they're
      initializing all their final variables or not. */
@@ -12700,9 +12701,12 @@ check_final_variable_global_assignment_f
 		nnctor++;
 	      }
 	    else
-	      parse_error_context
-		(lookup_cl (mdecl),
-		 "Final variable initialization error in this constructor");
+	      {
+		parse_error_context
+		  (lookup_cl (mdecl),
+		   "Final variable initialization error in this constructor");
+		error_found = 1;
+	      }
 	  }
 	else
 	  nnctor++;
@@ -12713,9 +12717,9 @@ check_final_variable_global_assignment_f
     if (FINAL_VARIABLE_P (field)
 	/* If the field wasn't initialized upon declaration */
 	&& !DECL_FIELD_FINAL_IUD (field)
-	/* There wasn't natural ctor in which the field could have been
-	   initialized */
-	&& !nnctor
+	/* There wasn't a natural ctor in which the field could have been
+	   initialized or we found an error looking for one. */
+	&& (error_found || !nnctor)
 	/* If we never reported a problem with this field */
 	&& !DECL_FIELD_FINAL_IERR (field))
       {
@@ -12725,7 +12729,6 @@ check_final_variable_global_assignment_f
 	   "Final variable `%s' hasn't been initialized upon its declaration",
 	   IDENTIFIER_POINTER (DECL_NAME (field)));
       }
-
 }
 
 /* Return 1 if an assignment to a FINAL is attempted in a non suitable


2001-09-27  Alexandre Petit-Bianco  <apbianco@redhat.com>

	* libjava.compile/final_initialization_in_ctor.java: New file

Index: libjava.compile/final_initialization_in_ctor.java
===================================================================
RCS file: final_initialization_in_ctor.java
diff -N final_initialization_in_ctor.java
--- /dev/null	Tue May  5 13:32:27 1998
+++ final_initialization_in_ctor.java	Thu Sep 27 11:41:47 2001
@@ -0,0 +1,21 @@
+// This test case was insipred by
+// http://gcc.gnu.org/ml/java/2001-09/msg00181.html
+
+class M {
+    int size () { return 3; }
+}
+
+class final_initialization_in_ctor {
+
+ final float loadFactor;
+
+  public final_initialization_in_ctor(M m)
+  {
+      this(Math.max(m.size() * 2, 30), (float)40.0);
+  }
+
+  public final_initialization_in_ctor(int initialCapacity, float loadFactor)
+  {
+      this.loadFactor = loadFactor;
+  }
+}


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]