This is the mail archive of the java-patches@gcc.gnu.org mailing list for the Java project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Patch: RFA: Fix PR java/21844


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


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]