This is the mail archive of the
java-patches@gcc.gnu.org
mailing list for the Java project.
Patch: RFA: Fix PR java/21844
- From: Tom Tromey <tromey at redhat dot com>
- To: Java Patch List <java-patches at gcc dot gnu dot org>
- Cc: Gcc Patch List <gcc-patches at gcc dot gnu dot org>
- Date: 06 Jun 2005 14:14:57 -0600
- Subject: Patch: RFA: Fix PR java/21844
- Reply-to: tromey at redhat dot com
This fixes PR java/21844.
The problem occurs if we are making an outer reference to an inherited
field. In this case nested_field_access_p incorrectly returned false,
and as a result we referenced the field against 'this' rather than
'this$0'. (Seems like this could be caught by type checking code in
some later pass, were it to exist.)
Tested on x86 FC2 including jacks. Test case included. Ok?
Tom
Index: libjava/ChangeLog
from Tom Tromey <tromey@redhat.com>
PR java/21844:
* testsuite/libjava.lang/pr21844.java: New file.
* testsuite/libjava.lang/pr21844.out: New file.
Index: gcc/java/ChangeLog
from Tom Tromey <tromey@redhat.com>
PR java/21844:
* parse.y (nested_field_access_p): Handle case where outer field
is inherited by enclosing class.
Index: gcc/java/parse.y
===================================================================
RCS file: /cvs/gcc/gcc/gcc/java/parse.y,v
retrieving revision 1.537
diff -u -r1.537 parse.y
--- gcc/java/parse.y 6 Jun 2005 19:31:35 -0000 1.537
+++ gcc/java/parse.y 6 Jun 2005 20:13:28 -0000
@@ -8416,6 +8416,13 @@
if (type_root == decl_type_root)
return 1;
+ /* Before we give up, see whether it is a non-static field
+ inherited from the enclosing context we are considering. */
+ if (!DECL_CONTEXT (TYPE_NAME (type_root))
+ && !is_static
+ && inherits_from_p (type_root, decl_type))
+ return 1;
+
return 0;
}
Index: libjava/testsuite/libjava.lang/pr21844.java
===================================================================
RCS file: libjava/testsuite/libjava.lang/pr21844.java
diff -N libjava/testsuite/libjava.lang/pr21844.java
--- /dev/null 1 Jan 1970 00:00:00 -0000
+++ libjava/testsuite/libjava.lang/pr21844.java 6 Jun 2005 20:13:28 -0000
@@ -0,0 +1,33 @@
+class pr21844base
+{
+ int modCount;
+
+ public pr21844base(int x)
+ {
+ modCount = x;
+ }
+}
+
+public class pr21844 extends pr21844base
+{
+ class inner
+ {
+ public int doit ()
+ {
+ ++modCount;
+ return modCount;
+ }
+ }
+
+ public pr21844(int x)
+ {
+ super(x);
+ }
+
+ public static void main(String[] args)
+ {
+ pr21844 val = new pr21844(7);
+ inner i = val.new inner();
+ System.out.println(i.doit());
+ }
+}
Index: libjava/testsuite/libjava.lang/pr21844.out
===================================================================
RCS file: libjava/testsuite/libjava.lang/pr21844.out
diff -N libjava/testsuite/libjava.lang/pr21844.out
--- /dev/null 1 Jan 1970 00:00:00 -0000
+++ libjava/testsuite/libjava.lang/pr21844.out 6 Jun 2005 20:13:28 -0000
@@ -0,0 +1 @@
+8