This is the mail archive of the
java-patches@sources.redhat.com
mailing list for the Java project.
Patch: error->warning when assigning to final field
- To: java-patches at sources dot redhat dot com
- Subject: Patch: error->warning when assigning to final field
- From: Per Bothner <per at bothner dot com>
- Date: 14 Jan 2001 09:48:36 -0800
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/