Treat deducible generic parameter types as unresolved types, because

they need to be substituted away for any type containing them to be
useful. A nice side-effect of this is that we'll actually properly
walk into the source type when a generic function returns, e.g., a
tuple type that involves type parameters not resolved by the input
arguments.


Swift SVN r2302
This commit is contained in:
Doug Gregor
2012-07-03 23:23:25 +00:00
parent 99fac3aaa8
commit ad2fa39eaa
2 changed files with 14 additions and 3 deletions

View File

@@ -1235,7 +1235,7 @@ class DeducibleGenericParamType : public SubstitutableType {
DeducibleGenericParamType(ASTContext &Ctx, Identifier Name, unsigned Index,
ArrayRef<ProtocolDecl *> ConformsTo)
: SubstitutableType(TypeKind::DeducibleGenericParam, &Ctx,
/*Unresolved=*/false, ConformsTo),
/*Unresolved=*/true, ConformsTo),
Name(Name), Index(Index) { }
public:

View File

@@ -228,7 +228,18 @@ class SemaCoerce : public ExprVisitor<SemaCoerce, CoercedResult> {
/// \brief Try to perform a user-defined conversion.
CoercedResult tryUserConversion(Expr *E);
/// \brief Determine whether the given types are the same, deducing
/// any deducible arguments along the way.
static bool sameType(Type T1, Type T2, CoercionContext &CC) {
// FIXME: This is really an approximation of the behavior we want, which
// would be to check for identical type structure while potentially
// deducing at each step.
bool Trivial;
return CC.TC.isSubtypeOf(T1, T2, Trivial, &CC) && Trivial &&
CC.TC.isSubtypeOf(T2, T1, Trivial, &CC) && Trivial;
}
public:
CoercedResult visitErrorExpr(ErrorExpr *E) {
return unchanged(E);
@@ -1488,7 +1499,7 @@ SemaCoerce::convertTupleToTupleType(Expr *E, unsigned NumExprElements,
// Because we have coerced something in the source tuple, we need to
// rebuild the type of that tuple.
RebuildSourceType = true;
} else if (ETy && !ElementTy->isEqual(DestEltTy)) {
} else if (ETy && !sameType(ElementTy, DestEltTy, CC)) {
// FIXME: Allow conversions when we don't have a tuple expression?
if (Flags & CF_Apply)
TC.diagnose(E->getLoc(), diag::tuple_element_type_mismatch, SrcField,