提交 d6003437 编写于 作者: M mcimadamore

6569404: Cannot instantiate an inner class of a type variable

Summary: javac is too strict in rejecting member selction from a type-var
Reviewed-by: jjg
上级 d9c71cf9
......@@ -1239,7 +1239,10 @@ public class Attr extends JCTree.Visitor {
}
if (site.tag == CLASS) {
if (site.getEnclosingType().tag == CLASS) {
Type encl = site.getEnclosingType();
while (encl != null && encl.tag == TYPEVAR)
encl = encl.getUpperBound();
if (encl.tag == CLASS) {
// we are calling a nested class
if (tree.meth.getTag() == JCTree.SELECT) {
......@@ -1251,7 +1254,7 @@ public class Attr extends JCTree.Visitor {
// to the outer instance type of the class.
chk.checkRefType(qualifier.pos(),
attribExpr(qualifier, localEnv,
site.getEnclosingType()));
encl));
} else if (methName == names._super) {
// qualifier omitted; check for existence
// of an appropriate implicit qualifier.
......@@ -2042,7 +2045,7 @@ public class Attr extends JCTree.Visitor {
Symbol sym = (site.getUpperBound() != null)
? selectSym(tree, capture(site.getUpperBound()), env, pt, pkind)
: null;
if (sym == null || isType(sym)) {
if (sym == null) {
log.error(pos, "type.var.cant.be.deref");
return syms.errSymbol;
} else {
......
/*
* Copyright 2009 Sun Microsystems, Inc. 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 Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
* CA 95054 USA or visit www.sun.com if you need additional information or
* have any questions.
*/
/*
* @test
* @bug 6569404
* @summary Regression: Cannot instantiate an inner class of a type variable
* @author mcimadamore
*/
public class T6569404a {
static class Outer {
public class Inner {}
}
static class Test<T extends Outer> {
public Test(T t) {
Outer.Inner inner = t.new Inner();
}
}
public static void main(String[] args) {
new Test<Outer>(new Outer());
}
}
/*
* Copyright 2009 Sun Microsystems, Inc. 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 Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
* CA 95054 USA or visit www.sun.com if you need additional information or
* have any questions.
*/
/*
* @test
* @bug 6569404
* @summary Regression: Cannot instantiate an inner class of a type variable
* @author mcimadamore
* @compile/fail/ref=T6569404b.out T6569404b.java -XDrawDiagnostics
*/
class T6569404b {
static class A<X> {}
static class B<T extends Outer> extends A<T.Inner> {}
static class Outer {
public class Inner {}
}
}
T6569404b.java:36:48: compiler.err.type.var.cant.be.deref
1 error
/*
* Copyright 2009 Sun Microsystems, Inc. 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 Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
* CA 95054 USA or visit www.sun.com if you need additional information or
* have any questions.
*/
/*
* @test
* @bug 6569404
* @summary Regression: Cannot instantiate an inner class of a type variable
* @author mcimadamore
*/
public class T6569404c {
static class Outer {
class Inner {}
}
static class Test<X extends Outer> {
class InnerTest extends X.Inner { InnerTest(Outer o) {o.super();} }
}
public static void main(String[] args) {
new Test<Outer>().new InnerTest(new Outer());
}
}
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册