# HG changeset patch # User mcimadamore # Date 1274283717 -3600 # Node ID e8aa492874b55d5b0f9145a4b4cd54a78ae761f1 # Parent 9a0b03523aa92a946553d80e0c39f977141ae675 6880344: Recursive type parameters do not compile Summary: Issue in type-variable substitution causes valid code to be rejected Reviewed-by: jjg diff -r 9a0b03523aa9 -r e8aa492874b5 langtools/src/share/classes/com/sun/tools/javac/code/Types.java --- a/langtools/src/share/classes/com/sun/tools/javac/code/Types.java Thu May 13 11:30:28 2010 -0700 +++ b/langtools/src/share/classes/com/sun/tools/javac/code/Types.java Wed May 19 16:41:57 2010 +0100 @@ -588,10 +588,21 @@ case BYTE: case CHAR: case SHORT: case INT: case LONG: case FLOAT: case DOUBLE: case BOOLEAN: case VOID: case BOT: case NONE: return t.tag == s.tag; - case TYPEVAR: - return s.isSuperBound() - && !s.isExtendsBound() - && visit(t, upperBound(s)); + case TYPEVAR: { + if (s.tag == TYPEVAR) { + //type-substitution does not preserve type-var types + //check that type var symbols and bounds are indeed the same + return t.tsym == s.tsym && + visit(t.getUpperBound(), s.getUpperBound()); + } + else { + //special case for s == ? super X, where upper(s) = u + //check that u == t, where u has been set by Type.withTypeVar + return s.isSuperBound() && + !s.isExtendsBound() && + visit(t, upperBound(s)); + } + } default: throw new AssertionError("isSameType " + t.tag); } diff -r 9a0b03523aa9 -r e8aa492874b5 langtools/src/share/classes/com/sun/tools/javac/comp/Check.java --- a/langtools/src/share/classes/com/sun/tools/javac/comp/Check.java Thu May 13 11:30:28 2010 -0700 +++ b/langtools/src/share/classes/com/sun/tools/javac/comp/Check.java Wed May 19 16:41:57 2010 +0100 @@ -915,7 +915,7 @@ List actuals = tree.type.allparams(); List args = tree.arguments; List forms = tree.type.tsym.type.getTypeArguments(); - ListBuffer tvars_buf = new ListBuffer(); + ListBuffer tvars_buf = new ListBuffer(); // For matching pairs of actual argument types `a' and // formal type parameters with declared bound `b' ... @@ -946,12 +946,15 @@ } args = tree.arguments; - List tvars = tvars_buf.toList(); + List tvars = tvars_buf.toList(); while (args.nonEmpty() && tvars.nonEmpty()) { + Type actual = types.subst(args.head.type, + tree.type.tsym.type.getTypeArguments(), + tvars_buf.toList()); checkExtends(args.head.pos(), - args.head.type, - tvars.head); + actual, + (TypeVar)tvars.head); args = args.tail; tvars = tvars.tail; } diff -r 9a0b03523aa9 -r e8aa492874b5 langtools/test/tools/javac/generics/typevars/T6880344.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/langtools/test/tools/javac/generics/typevars/T6880344.java Wed May 19 16:41:57 2010 +0100 @@ -0,0 +1,40 @@ +/* + * 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 6880344 + * @summary Recursive type parameters do not compile + * @author mcimadamore + * @compile T6880344.java + */ + +class T6880344 { + static class A> { + public A> xyz; + } + + static class N> implements G> { } + + interface G> { } +}