Patch: error->warning when assigning to final field

Per Bothner per@bothner.com
Sun Jan 14 09:43:00 GMT 2001


I checked in the following.  It changes an error to a warning when
assigning to a final field outside an initializer.  An error is not
appropriate, since assigning outside an initializer does not violate
the JVM Spec, and Sun's verifier does not complain.  A warning *is*
appropriate - for one thing MicroSoft's verifier *does* complain.
(I have gotten reports on this from people using Kawa.)

(I've got a couple of back-logged patches.  I should perhaps let people
evaluate them before checking them in, but there are three logically
different patches in one file, and dealing with them twice would be a
pain.)

2001-01-13  Per Bothner  <per@bothner.com>

	* expr.c (expand_java_field_op):  Assigning to a final field outside
	an initializer does not violate JVM spec, so should be warning, not
	error.  (Sun's verifier does not complain - though MicroSoft's does.)

Index: expr.c
===================================================================
RCS file: /cvs/gcc/egcs/gcc/java/expr.c,v
retrieving revision 1.93
diff -u -r1.93 expr.c
--- expr.c	2001/01/10 23:06:30	1.93
+++ expr.c	2001/01/14 17:32:12
@@ -2215,7 +2215,7 @@
 	  else if (FIELD_STATIC (field_decl))
 	    {
 	      if (!DECL_CLINIT_P (current_function_decl))
-		error_with_decl (field_decl, 
+		warning_with_decl (field_decl, 
              "assignment to final static field `%s' not in class initializer");
 	    }
 	  else
@@ -2223,7 +2223,7 @@
 	      tree cfndecl_name = DECL_NAME (current_function_decl);
 	      if (! DECL_CONSTRUCTOR_P (current_function_decl)
 		  && !ID_FINIT_P (cfndecl_name))
-		error_with_decl (field_decl, "assignment to final field `%s' not in constructor");
+		warning_with_decl (field_decl, "assignment to final field `%s' not in constructor");
 	    }
 	}
       expand_assignment (field_ref, new_value, 0, 0);

-- 
	--Per Bothner
per@bothner.com   http://www.bothner.com/~per/


More information about the Java-patches mailing list