This is the mail archive of the
java-patches@gcc.gnu.org
mailing list for the Java project.
Java: Fix for PR 5850
- From: Bryce McKinlay <bryce at waitaki dot otago dot ac dot nz>
- To: java-patches at gcc dot gnu dot org, gcc-patches at gcc dot gnu dot org
- Date: Wed, 27 Mar 2002 16:44:43 +1200
- Subject: Java: Fix for PR 5850
This patch fixes field lookups to work more like they are supposed to
according to the JLS.
Previously it would search in enclosing contexts before it has searched
in all the supertypes of the current class, which is wrong. It could
also find a field in an enclosing context of a supertype, which is also
wrong. This change fixes both those bugs.
Rebuilt libjava and ran testsuite without regressions. Also rebuilt
freenet. OK to commit?
regards
Bryce.
2002-03-27 Bryce McKinlay <bryce@waitaki.otago.ac.nz>
Fix for PR java/5850:
* parse.y (lookup_field_wrapper): Call itself recursively for enclosing
context if nothing was found in the current context.
* expr.c (lookup_field): Don't look in enclosing contexts.
Index: parse.y
===================================================================
RCS file: /cvs/gcc/gcc/gcc/java/parse.y,v
retrieving revision 1.364
diff -u -r1.364 parse.y
--- parse.y 2002/03/26 18:59:04 1.364
+++ parse.y 2002/03/27 03:29:26
@@ -4209,6 +4209,13 @@
decl = lookup_field (&type, name);
}
+ /* If the field still hasn't been found, try the next enclosing context. */
+ if (!decl && INNER_CLASS_TYPE_P (class))
+ {
+ tree outer_type = TREE_TYPE (DECL_CONTEXT (TYPE_NAME (class)));
+ decl = lookup_field_wrapper (outer_type, name);
+ }
+
java_parser_context_restore_global ();
return decl == error_mark_node ? NULL : decl;
}
Index: expr.c
===================================================================
RCS file: /cvs/gcc/gcc/gcc/java/expr.c,v
retrieving revision 1.138
diff -u -r1.138 expr.c
--- expr.c 2002/03/23 01:19:40 1.138
+++ expr.c 2002/03/27 03:29:26
@@ -1517,16 +1517,6 @@
if (DECL_NAME (field) == name)
return field;
- /* If *typep is an innerclass, lookup the field in its enclosing
- contexts */
- if (INNER_CLASS_TYPE_P (*typep))
- {
- tree outer_type = TREE_TYPE (DECL_CONTEXT (TYPE_NAME (*typep)));
-
- if ((field = lookup_field (&outer_type, name)))
- return field;
- }
-
/* Process implemented interfaces. */
basetype_vec = TYPE_BINFO_BASETYPES (*typep);
n = TREE_VEC_LENGTH (basetype_vec);