# HG changeset patch # User mcimadamore # Date 1282215265 -3600 # Node ID a75770c0d7f6c267554a361d3d4a8d11a6d3e386 # Parent d6fe0ea070aa7aebf8b9917c48adebefc7445f82 6977800: Regression: invalid resolution of supertype for local class Summary: resolution of superclass/superinterfaces in extends/implements clause skips local classes Reviewed-by: jjg diff -r d6fe0ea070aa -r a75770c0d7f6 src/share/classes/com/sun/tools/javac/comp/Check.java --- a/src/share/classes/com/sun/tools/javac/comp/Check.java Thu Aug 19 11:52:58 2010 +0100 +++ b/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); diff -r d6fe0ea070aa -r a75770c0d7f6 src/share/classes/com/sun/tools/javac/comp/MemberEnter.java --- a/src/share/classes/com/sun/tools/javac/comp/MemberEnter.java Thu Aug 19 11:52:58 2010 +0100 +++ b/src/share/classes/com/sun/tools/javac/comp/MemberEnter.java Thu Aug 19 11:54:25 2010 +0100 @@ -1079,14 +1079,21 @@ private Env baseEnv(JCClassDecl tree, Env 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 typarams = tree.typarams; typarams.nonEmpty(); typarams = typarams.tail) - typaramScope.enter(typarams.head.type.tsym); + baseScope.enter(typarams.head.type.tsym); Env outer = env.outer; // the base clause can't see members of this class - Env localEnv = outer.dup(tree, outer.info.dup(typaramScope)); + Env localEnv = outer.dup(tree, outer.info.dup(baseScope)); localEnv.baseClause = true; localEnv.outer = outer; localEnv.info.isSelfCall = false; diff -r d6fe0ea070aa -r a75770c0d7f6 test/tools/javac/T6977800.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/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 {} +} diff -r d6fe0ea070aa -r a75770c0d7f6 test/tools/javac/generics/typevars/5060485/Compatibility.java --- a/test/tools/javac/generics/typevars/5060485/Compatibility.java Thu Aug 19 11:52:58 2010 +0100 +++ b/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 {} diff -r d6fe0ea070aa -r a75770c0d7f6 test/tools/javac/generics/typevars/5060485/Compatibility.out --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/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 diff -r d6fe0ea070aa -r a75770c0d7f6 test/tools/javac/generics/typevars/5060485/Compatibility02.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/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 {} + +class Test { + void m() { + static class Y {} + class Y1> {} + } +} diff -r d6fe0ea070aa -r a75770c0d7f6 test/tools/javac/generics/typevars/5060485/Compatibility02.out --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/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