6977800: Regression: invalid resolution of supertype for local class
Resolution of superclass/superinterfaces in extends/implements clause skips local classes Reviewed-by: jjg
This commit is contained in:
parent
d56e09153a
commit
634d001c64
@ -330,7 +330,7 @@ public class Check {
|
||||
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);
|
||||
|
@ -1079,14 +1079,21 @@ public class MemberEnter extends JCTree.Visitor implements Completer {
|
||||
|
||||
|
||||
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;
|
||||
|
41
langtools/test/tools/javac/T6977800.java
Normal file
41
langtools/test/tools/javac/T6977800.java
Normal file
@ -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 {}
|
||||
}
|
@ -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> {}
|
||||
|
@ -0,0 +1,2 @@
|
||||
Compatibility.java:36:35: compiler.err.not.within.bounds: Test.Y
|
||||
1 error
|
@ -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>> {}
|
||||
}
|
||||
}
|
@ -0,0 +1,2 @@
|
||||
Compatibility.java:36:35: compiler.err.not.within.bounds: Test.Y
|
||||
1 error
|
Loading…
x
Reference in New Issue
Block a user