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]

Java: fix ambiguous qualified name scope bug


An ambiguous qualified name should be resolved by first considering the 
enclosing scope of the current class. If the first part of the name 
matches a type declared within the current scope, then that type should 
be used. See the JLS, 2nd ed, S6.5.2.

GCJ gets this backwards. It only considers package scope and in fact 
will report an error if the type does not exist in the package scope, 
such as in this example:

package X;

class X
{
  class Y {}
 
  public static void main(String[] args)
  {
    System.out.println (X.Y.class);
  }
}

X/X.java: In class `X.X':
X/X.java: In method `X.X.main(java.lang.String[])':
X/X.java:9: Class `X.Y' not found in type declaration.
       System.out.println (X.Y.class);
                           ^
1 error


If we also declare a top-level class named X.Y, GCJ will select the 
wrong class:
$ gcj -C X/X.java
$ gij X.X
class X.Y

$ javac X/X.java
$ gij X.X
class X.X$Y

The patch below corrects this bug so that correct code will compile 
(correctly). There is an additional problem in that name resolution 
continues when the ambiguous name is not found within the closest scope 
- eg:

package X;

class Y {}

class X
{ 
  public static void main(String[] args)
  {
    System.out.println (X.Y.class);
  }
}

This should be an error, but GCJ will take it to mean the top level 
class "X.Y". This seems harder to fix, and the patch does not address 
that. I'll post a PR for this one.

OK to commit?

regards

Bryce.








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