6977800: Regression: invalid resolution of supertype for local class
authormcimadamore
Thu, 19 Aug 2010 11:54:25 +0100
changeset 6352 217d5a69681a
parent 6351 84c44db80d06
child 6353 bb5c39054bf3
6977800: Regression: invalid resolution of supertype for local class Summary: resolution of superclass/superinterfaces in extends/implements clause skips local classes Reviewed-by: jjg
langtools/src/share/classes/com/sun/tools/javac/comp/Check.java
langtools/src/share/classes/com/sun/tools/javac/comp/MemberEnter.java
langtools/test/tools/javac/T6977800.java
langtools/test/tools/javac/generics/typevars/5060485/Compatibility.java
langtools/test/tools/javac/generics/typevars/5060485/Compatibility.out
langtools/test/tools/javac/generics/typevars/5060485/Compatibility02.java
langtools/test/tools/javac/generics/typevars/5060485/Compatibility02.out
--- a/langtools/src/share/classes/com/sun/tools/javac/comp/Check.java	Thu Aug 19 11:52:58 2010 +0100
+++ b/langtools/src/share/classes/com/sun/tools/javac/comp/Check.java	Thu Aug 19 11:54:25 2010 +0100
@@ -330,7 +330,7 @@
             for (Scope.Entry e = s.next.lookup(c.name);
                  e.scope != null && e.sym.owner == c.owner;
                  e = e.next()) {
-                if (e.sym.kind == TYP &&
+                if (e.sym.kind == TYP && e.sym.type.tag != TYPEVAR &&
                     (e.sym.owner.kind & (VAR | MTH)) != 0 &&
                     c.name != names.error) {
                     duplicateError(pos, e.sym);
--- a/langtools/src/share/classes/com/sun/tools/javac/comp/MemberEnter.java	Thu Aug 19 11:52:58 2010 +0100
+++ b/langtools/src/share/classes/com/sun/tools/javac/comp/MemberEnter.java	Thu Aug 19 11:54:25 2010 +0100
@@ -1079,14 +1079,21 @@
 
 
     private Env<AttrContext> baseEnv(JCClassDecl tree, Env<AttrContext> env) {
-        Scope typaramScope = new Scope(tree.sym);
+        Scope baseScope = new Scope(tree.sym);
+        //import already entered local classes into base scope
+        for (Scope.Entry e = env.outer.info.scope.elems ; e != null ; e = e.sibling) {
+            if (e.sym.isLocal()) {
+                baseScope.enter(e.sym);
+            }
+        }
+        //import current type-parameters into base scope
         if (tree.typarams != null)
             for (List<JCTypeParameter> typarams = tree.typarams;
                  typarams.nonEmpty();
                  typarams = typarams.tail)
-                typaramScope.enter(typarams.head.type.tsym);
+                baseScope.enter(typarams.head.type.tsym);
         Env<AttrContext> outer = env.outer; // the base clause can't see members of this class
-        Env<AttrContext> localEnv = outer.dup(tree, outer.info.dup(typaramScope));
+        Env<AttrContext> localEnv = outer.dup(tree, outer.info.dup(baseScope));
         localEnv.baseClause = true;
         localEnv.outer = outer;
         localEnv.info.isSelfCall = false;
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/langtools/test/tools/javac/T6977800.java	Thu Aug 19 11:54:25 2010 +0100
@@ -0,0 +1,41 @@
+/*
+ * Copyright (c) 2010, Oracle and/or its affiliates. All rights reserved.
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+ *
+ * This code is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License version 2 only, as
+ * published by the Free Software Foundation.
+ *
+ * This code is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
+ * version 2 for more details (a copy is included in the LICENSE file that
+ * accompanied this code).
+ *
+ * You should have received a copy of the GNU General Public License version
+ * 2 along with this work; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+ *
+ * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
+ * or visit www.oracle.com if you need additional information or have any
+ * questions.
+ */
+
+/*
+ * @test
+ * @bug 6977800
+ * @summary Regression: invalid resolution of supertype for local class
+ * @compile T6977800.java
+ */
+
+class T6977800 {
+    public static void test() {
+        class A {
+            int x = 1;
+        }
+        class B extends A {}
+        System.out.println(new B().x);
+    }
+
+    static class A {}
+}
--- a/langtools/test/tools/javac/generics/typevars/5060485/Compatibility.java	Thu Aug 19 11:52:58 2010 +0100
+++ b/langtools/test/tools/javac/generics/typevars/5060485/Compatibility.java	Thu Aug 19 11:54:25 2010 +0100
@@ -26,7 +26,7 @@
  * @bug     5060485
  * @summary The scope of a class type parameter is too wide
  * @author  Peter von der Ah\u00e9
- * @compile/fail Compatibility.java
+ * @compile/fail/ref=Compatibility.out -XDrawDiagnostics Compatibility.java
  */
 
 class NumberList<T extends Number> {}
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/langtools/test/tools/javac/generics/typevars/5060485/Compatibility.out	Thu Aug 19 11:54:25 2010 +0100
@@ -0,0 +1,2 @@
+Compatibility.java:36:35: compiler.err.not.within.bounds: Test.Y
+1 error
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/langtools/test/tools/javac/generics/typevars/5060485/Compatibility02.java	Thu Aug 19 11:54:25 2010 +0100
@@ -0,0 +1,39 @@
+/*
+ * Copyright (c) 2006, Oracle and/or its affiliates. All rights reserved.
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+ *
+ * This code is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License version 2 only, as
+ * published by the Free Software Foundation.
+ *
+ * This code is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
+ * version 2 for more details (a copy is included in the LICENSE file that
+ * accompanied this code).
+ *
+ * You should have received a copy of the GNU General Public License version
+ * 2 along with this work; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+ *
+ * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
+ * or visit www.oracle.com if you need additional information or have any
+ * questions.
+ */
+
+/*
+ * @test
+ * @bug     5060485 6977800
+ * @summary The scope of a class type parameter is too wide
+ * @author  Maurizio Cimadamore
+ * @compile/fail/ref=Compatibility02.out -XDrawDiagnostics Compatibility.java
+ */
+
+class NumberList<T extends Number> {}
+
+class Test {
+    <Y extends Number> void m() {
+        static class Y {}
+        class Y1<S extends NumberList<Y>> {}
+    }
+}
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/langtools/test/tools/javac/generics/typevars/5060485/Compatibility02.out	Thu Aug 19 11:54:25 2010 +0100
@@ -0,0 +1,2 @@
+Compatibility.java:36:35: compiler.err.not.within.bounds: Test.Y
+1 error