Java: Fix for PR java/5935

Bryce McKinlay bryce@waitaki.otago.ac.nz
Thu Mar 14 08:06:00 GMT 2002


So basically, this bug occurs when there are anonymous classes declared 
in multiple methods with the same "final" parameters signature, but 
different parameter names (and those parameters are acutally used). What 
happens is that craft_constructor calls build_function_type to generate 
a method_type which includes the implicitly passed "final" arguments to 
its enclosing method, and then fix_method_argument_names to set the 
names of the arguments within the method_type parameter list. However, 
build_function_type is smart, and reuses the same tree_list nodes if it 
finds the function has the same signature as a previous function type. 
Anonymous class constructors are a special case and do not get laid 
out/implemented until after everything else has been expanded, so 
fix_method_argument_names ends up changing the parameter names on 
method_type tree_list nodes which are shared with other anonymous 
constructor decls. When the body of each anonymous constructor is 
eventually generated, the wrong parameter name is used and if that 
parameter is actually referenced within the anonymous class body, we get 
an error. Yucky.

The solution is simply to call fix_constructors (should really be called 
"implement_constructor_body", except that it does something else as 
well) right after craft_constructor. This ensures that another anonymous 
class declaration doesnt get the chance to clobber over the existing 
parameter names.

Rebuilt libjava and ran test suite with no regressions on 3.1 branch, 
PowerPC linux. Java on mainline seems to have regressions but they aint 
caused by this patch. OK to commit?

regards

Bryce.


-------------- next part --------------
An embedded and charset-unspecified text was scrubbed...
Name: java-5935.patch
URL: <http://gcc.gnu.org/pipermail/java-patches/attachments/20020314/cfb943ea/attachment.ksh>


More information about the Java-patches mailing list