# HG changeset patch # User mcimadamore # Date 1249949646 -3600 # Node ID 13902c0c9b832cdf5c6241f43048548606dd1687 # Parent 62fb6cafa93b868ff0b3819ba500180e0a335c67 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 diff -r 62fb6cafa93b -r 13902c0c9b83 src/share/classes/com/sun/tools/javac/comp/Attr.java --- a/src/share/classes/com/sun/tools/javac/comp/Attr.java Tue Aug 11 01:13:42 2009 +0100 +++ b/src/share/classes/com/sun/tools/javac/comp/Attr.java Tue Aug 11 01:14:06 2009 +0100 @@ -1239,7 +1239,10 @@ } 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 @@ // 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 @@ 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 { diff -r 62fb6cafa93b -r 13902c0c9b83 test/tools/javac/generics/typevars/6569404/T6569404a.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/test/tools/javac/generics/typevars/6569404/T6569404a.java Tue Aug 11 01:14:06 2009 +0100 @@ -0,0 +1,46 @@ +/* + * 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 { + public Test(T t) { + Outer.Inner inner = t.new Inner(); + } + } + + public static void main(String[] args) { + new Test(new Outer()); + } +} diff -r 62fb6cafa93b -r 13902c0c9b83 test/tools/javac/generics/typevars/6569404/T6569404b.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/test/tools/javac/generics/typevars/6569404/T6569404b.java Tue Aug 11 01:14:06 2009 +0100 @@ -0,0 +1,41 @@ +/* + * 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 {} + + static class B extends A {} + + static class Outer { + public class Inner {} + } +} diff -r 62fb6cafa93b -r 13902c0c9b83 test/tools/javac/generics/typevars/6569404/T6569404b.out --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/test/tools/javac/generics/typevars/6569404/T6569404b.out Tue Aug 11 01:14:06 2009 +0100 @@ -0,0 +1,2 @@ +T6569404b.java:36:48: compiler.err.type.var.cant.be.deref +1 error diff -r 62fb6cafa93b -r 13902c0c9b83 test/tools/javac/generics/typevars/6569404/T6569404c.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/test/tools/javac/generics/typevars/6569404/T6569404c.java Tue Aug 11 01:14:06 2009 +0100 @@ -0,0 +1,43 @@ +/* + * 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 { + class InnerTest extends X.Inner { InnerTest(Outer o) {o.super();} } + } + + public static void main(String[] args) { + new Test().new InnerTest(new Outer()); + } +}