7148242: Regression: valid code rejected during generic type well-formedness check

Redundant type-var substitution makes generic-type well-formedness check to fail

Reviewed-by: jjg
This commit is contained in:
Maurizio Cimadamore 2012-03-02 12:57:47 +00:00
parent f01bc46dfe
commit b10e766b73
2 changed files with 52 additions and 21 deletions

View file

@ -525,16 +525,16 @@ public class Check {
* @param a The type that should be bounded by bs. * @param a The type that should be bounded by bs.
* @param bs The bound. * @param bs The bound.
*/ */
private boolean checkExtends(Type a, TypeVar bs) { private boolean checkExtends(Type a, Type bound) {
if (a.isUnbound()) { if (a.isUnbound()) {
return true; return true;
} else if (a.tag != WILDCARD) { } else if (a.tag != WILDCARD) {
a = types.upperBound(a); a = types.upperBound(a);
return types.isSubtype(a, bs.bound); return types.isSubtype(a, bound);
} else if (a.isExtendsBound()) { } else if (a.isExtendsBound()) {
return types.isCastable(bs.getUpperBound(), types.upperBound(a), Warner.noWarnings); return types.isCastable(bound, types.upperBound(a), Warner.noWarnings);
} else if (a.isSuperBound()) { } else if (a.isSuperBound()) {
return !types.notSoftSubtype(types.lowerBound(a), bs.getUpperBound()); return !types.notSoftSubtype(types.lowerBound(a), bound);
} }
return true; return true;
} }
@ -776,18 +776,16 @@ public class Check {
List<Type> actuals = type.allparams(); List<Type> actuals = type.allparams();
List<Type> args = type.getTypeArguments(); List<Type> args = type.getTypeArguments();
List<Type> forms = type.tsym.type.getTypeArguments(); List<Type> forms = type.tsym.type.getTypeArguments();
ListBuffer<Type> tvars_buf = new ListBuffer<Type>(); ListBuffer<Type> bounds_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' ...
while (args.nonEmpty() && forms.nonEmpty()) { while (args.nonEmpty() && forms.nonEmpty()) {
// exact type arguments needs to know their // exact type arguments needs to know their
// bounds (for upper and lower bound // bounds (for upper and lower bound
// calculations). So we create new TypeVars with // calculations). So we create new bounds where
// bounds substed with actuals. // type-parameters are replaced with actuals argument types.
tvars_buf.append(types.substBound(((TypeVar)forms.head), bounds_buf.append(types.subst(forms.head.getUpperBound(), formals, actuals));
formals,
actuals));
args = args.tail; args = args.tail;
forms = forms.tail; forms = forms.tail;
} }
@ -804,32 +802,30 @@ public class Check {
} }
args = type.getTypeArguments(); args = type.getTypeArguments();
List<Type> tvars = tvars_buf.toList(); List<Type> bounds = bounds_buf.toList();
while (args.nonEmpty() && tvars.nonEmpty()) { while (args.nonEmpty() && bounds.nonEmpty()) {
Type actual = types.subst(args.head, Type actual = args.head;
type.tsym.type.getTypeArguments(),
tvars_buf.toList());
if (!isTypeArgErroneous(actual) && if (!isTypeArgErroneous(actual) &&
!tvars.head.getUpperBound().isErroneous() && !bounds.head.isErroneous() &&
!checkExtends(actual, (TypeVar)tvars.head)) { !checkExtends(actual, bounds.head)) {
return args.head; return args.head;
} }
args = args.tail; args = args.tail;
tvars = tvars.tail; bounds = bounds.tail;
} }
args = type.getTypeArguments(); args = type.getTypeArguments();
tvars = tvars_buf.toList(); bounds = bounds_buf.toList();
for (Type arg : types.capture(type).getTypeArguments()) { for (Type arg : types.capture(type).getTypeArguments()) {
if (arg.tag == TYPEVAR && if (arg.tag == TYPEVAR &&
arg.getUpperBound().isErroneous() && arg.getUpperBound().isErroneous() &&
!tvars.head.getUpperBound().isErroneous() && !bounds.head.isErroneous() &&
!isTypeArgErroneous(args.head)) { !isTypeArgErroneous(args.head)) {
return args.head; return args.head;
} }
tvars = tvars.tail; bounds = bounds.tail;
args = args.tail; args = args.tail;
} }

View file

@ -0,0 +1,35 @@
/*
* Copyright (c) 2009, 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 7148242
* @summary Regression: valid code rejected during generic type well-formedness check
* @compile T7148242.java
*/
class T7148242 {
static abstract class A<K, V, I extends Pair<K, V>, I2 extends Pair<V, K>> {
abstract A<V, K, I2, I> test();
}
static class Pair<K, V> { }
}