Thu, 19 Aug 2010 11:54:25 +0100
6977800: Regression: invalid resolution of supertype for local class
Summary: resolution of superclass/superinterfaces in extends/implements clause skips local classes
Reviewed-by: jjg
1.1 --- a/src/share/classes/com/sun/tools/javac/comp/Check.java Thu Aug 19 11:52:58 2010 +0100 1.2 +++ b/src/share/classes/com/sun/tools/javac/comp/Check.java Thu Aug 19 11:54:25 2010 +0100 1.3 @@ -330,7 +330,7 @@ 1.4 for (Scope.Entry e = s.next.lookup(c.name); 1.5 e.scope != null && e.sym.owner == c.owner; 1.6 e = e.next()) { 1.7 - if (e.sym.kind == TYP && 1.8 + if (e.sym.kind == TYP && e.sym.type.tag != TYPEVAR && 1.9 (e.sym.owner.kind & (VAR | MTH)) != 0 && 1.10 c.name != names.error) { 1.11 duplicateError(pos, e.sym);
2.1 --- a/src/share/classes/com/sun/tools/javac/comp/MemberEnter.java Thu Aug 19 11:52:58 2010 +0100 2.2 +++ b/src/share/classes/com/sun/tools/javac/comp/MemberEnter.java Thu Aug 19 11:54:25 2010 +0100 2.3 @@ -1079,14 +1079,21 @@ 2.4 2.5 2.6 private Env<AttrContext> baseEnv(JCClassDecl tree, Env<AttrContext> env) { 2.7 - Scope typaramScope = new Scope(tree.sym); 2.8 + Scope baseScope = new Scope(tree.sym); 2.9 + //import already entered local classes into base scope 2.10 + for (Scope.Entry e = env.outer.info.scope.elems ; e != null ; e = e.sibling) { 2.11 + if (e.sym.isLocal()) { 2.12 + baseScope.enter(e.sym); 2.13 + } 2.14 + } 2.15 + //import current type-parameters into base scope 2.16 if (tree.typarams != null) 2.17 for (List<JCTypeParameter> typarams = tree.typarams; 2.18 typarams.nonEmpty(); 2.19 typarams = typarams.tail) 2.20 - typaramScope.enter(typarams.head.type.tsym); 2.21 + baseScope.enter(typarams.head.type.tsym); 2.22 Env<AttrContext> outer = env.outer; // the base clause can't see members of this class 2.23 - Env<AttrContext> localEnv = outer.dup(tree, outer.info.dup(typaramScope)); 2.24 + Env<AttrContext> localEnv = outer.dup(tree, outer.info.dup(baseScope)); 2.25 localEnv.baseClause = true; 2.26 localEnv.outer = outer; 2.27 localEnv.info.isSelfCall = false;
3.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 3.2 +++ b/test/tools/javac/T6977800.java Thu Aug 19 11:54:25 2010 +0100 3.3 @@ -0,0 +1,41 @@ 3.4 +/* 3.5 + * Copyright (c) 2010, Oracle and/or its affiliates. All rights reserved. 3.6 + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 3.7 + * 3.8 + * This code is free software; you can redistribute it and/or modify it 3.9 + * under the terms of the GNU General Public License version 2 only, as 3.10 + * published by the Free Software Foundation. 3.11 + * 3.12 + * This code is distributed in the hope that it will be useful, but WITHOUT 3.13 + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 3.14 + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 3.15 + * version 2 for more details (a copy is included in the LICENSE file that 3.16 + * accompanied this code). 3.17 + * 3.18 + * You should have received a copy of the GNU General Public License version 3.19 + * 2 along with this work; if not, write to the Free Software Foundation, 3.20 + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. 3.21 + * 3.22 + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA 3.23 + * or visit www.oracle.com if you need additional information or have any 3.24 + * questions. 3.25 + */ 3.26 + 3.27 +/* 3.28 + * @test 3.29 + * @bug 6977800 3.30 + * @summary Regression: invalid resolution of supertype for local class 3.31 + * @compile T6977800.java 3.32 + */ 3.33 + 3.34 +class T6977800 { 3.35 + public static void test() { 3.36 + class A { 3.37 + int x = 1; 3.38 + } 3.39 + class B extends A {} 3.40 + System.out.println(new B().x); 3.41 + } 3.42 + 3.43 + static class A {} 3.44 +}
4.1 --- a/test/tools/javac/generics/typevars/5060485/Compatibility.java Thu Aug 19 11:52:58 2010 +0100 4.2 +++ b/test/tools/javac/generics/typevars/5060485/Compatibility.java Thu Aug 19 11:54:25 2010 +0100 4.3 @@ -26,7 +26,7 @@ 4.4 * @bug 5060485 4.5 * @summary The scope of a class type parameter is too wide 4.6 * @author Peter von der Ah\u00e9 4.7 - * @compile/fail Compatibility.java 4.8 + * @compile/fail/ref=Compatibility.out -XDrawDiagnostics Compatibility.java 4.9 */ 4.10 4.11 class NumberList<T extends Number> {}
5.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 5.2 +++ b/test/tools/javac/generics/typevars/5060485/Compatibility.out Thu Aug 19 11:54:25 2010 +0100 5.3 @@ -0,0 +1,2 @@ 5.4 +Compatibility.java:36:35: compiler.err.not.within.bounds: Test.Y 5.5 +1 error
6.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 6.2 +++ b/test/tools/javac/generics/typevars/5060485/Compatibility02.java Thu Aug 19 11:54:25 2010 +0100 6.3 @@ -0,0 +1,39 @@ 6.4 +/* 6.5 + * Copyright (c) 2006, Oracle and/or its affiliates. All rights reserved. 6.6 + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 6.7 + * 6.8 + * This code is free software; you can redistribute it and/or modify it 6.9 + * under the terms of the GNU General Public License version 2 only, as 6.10 + * published by the Free Software Foundation. 6.11 + * 6.12 + * This code is distributed in the hope that it will be useful, but WITHOUT 6.13 + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 6.14 + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 6.15 + * version 2 for more details (a copy is included in the LICENSE file that 6.16 + * accompanied this code). 6.17 + * 6.18 + * You should have received a copy of the GNU General Public License version 6.19 + * 2 along with this work; if not, write to the Free Software Foundation, 6.20 + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. 6.21 + * 6.22 + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA 6.23 + * or visit www.oracle.com if you need additional information or have any 6.24 + * questions. 6.25 + */ 6.26 + 6.27 +/* 6.28 + * @test 6.29 + * @bug 5060485 6977800 6.30 + * @summary The scope of a class type parameter is too wide 6.31 + * @author Maurizio Cimadamore 6.32 + * @compile/fail/ref=Compatibility02.out -XDrawDiagnostics Compatibility.java 6.33 + */ 6.34 + 6.35 +class NumberList<T extends Number> {} 6.36 + 6.37 +class Test { 6.38 + <Y extends Number> void m() { 6.39 + static class Y {} 6.40 + class Y1<S extends NumberList<Y>> {} 6.41 + } 6.42 +}
7.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 7.2 +++ b/test/tools/javac/generics/typevars/5060485/Compatibility02.out Thu Aug 19 11:54:25 2010 +0100 7.3 @@ -0,0 +1,2 @@ 7.4 +Compatibility.java:36:35: compiler.err.not.within.bounds: Test.Y 7.5 +1 error