6880344: Recursive type parameters do not compile

Issue in type-variable substitution causes valid code to be rejected

Reviewed-by: jjg
This commit is contained in:
Maurizio Cimadamore 2010-05-19 16:41:57 +01:00
parent 7648a5f5ef
commit 1bc9b6324e
3 changed files with 62 additions and 8 deletions

View File

@ -588,10 +588,21 @@ public class Types {
case BYTE: case CHAR: case SHORT: case INT: case LONG: case FLOAT: case BYTE: case CHAR: case SHORT: case INT: case LONG: case FLOAT:
case DOUBLE: case BOOLEAN: case VOID: case BOT: case NONE: case DOUBLE: case BOOLEAN: case VOID: case BOT: case NONE:
return t.tag == s.tag; return t.tag == s.tag;
case TYPEVAR: case TYPEVAR: {
return s.isSuperBound() if (s.tag == TYPEVAR) {
&& !s.isExtendsBound() //type-substitution does not preserve type-var types
&& visit(t, upperBound(s)); //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: default:
throw new AssertionError("isSameType " + t.tag); throw new AssertionError("isSameType " + t.tag);
} }

View File

@ -915,7 +915,7 @@ public class Check {
List<Type> actuals = tree.type.allparams(); List<Type> actuals = tree.type.allparams();
List<JCExpression> args = tree.arguments; List<JCExpression> args = tree.arguments;
List<Type> forms = tree.type.tsym.type.getTypeArguments(); List<Type> forms = tree.type.tsym.type.getTypeArguments();
ListBuffer<TypeVar> tvars_buf = new ListBuffer<TypeVar>(); ListBuffer<Type> tvars_buf = new ListBuffer<Type>();
// For matching pairs of actual argument types `a' and // For matching pairs of actual argument types `a' and
// formal type parameters with declared bound `b' ... // formal type parameters with declared bound `b' ...
@ -946,12 +946,15 @@ public class Check {
} }
args = tree.arguments; args = tree.arguments;
List<TypeVar> tvars = tvars_buf.toList(); List<Type> tvars = tvars_buf.toList();
while (args.nonEmpty() && tvars.nonEmpty()) { while (args.nonEmpty() && tvars.nonEmpty()) {
Type actual = types.subst(args.head.type,
tree.type.tsym.type.getTypeArguments(),
tvars_buf.toList());
checkExtends(args.head.pos(), checkExtends(args.head.pos(),
args.head.type, actual,
tvars.head); (TypeVar)tvars.head);
args = args.tail; args = args.tail;
tvars = tvars.tail; tvars = tvars.tail;
} }

View File

@ -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<X1 extends G<X1>> {
public A<N<X1>> xyz;
}
static class N<X2 extends G<X2>> implements G<N<X2>> { }
interface G<X3 extends G<X3>> { }
}