From ad2fa39eaaa5152cccedcf165dc5dde08dea036c Mon Sep 17 00:00:00 2001 From: Doug Gregor Date: Tue, 3 Jul 2012 23:23:25 +0000 Subject: [PATCH] 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 --- include/swift/AST/Types.h | 2 +- lib/Sema/TypeCheckCoercion.cpp | 15 +++++++++++++-- 2 files changed, 14 insertions(+), 3 deletions(-) diff --git a/include/swift/AST/Types.h b/include/swift/AST/Types.h index 4e57b9ca35c..f390f4ce60a 100644 --- a/include/swift/AST/Types.h +++ b/include/swift/AST/Types.h @@ -1235,7 +1235,7 @@ class DeducibleGenericParamType : public SubstitutableType { DeducibleGenericParamType(ASTContext &Ctx, Identifier Name, unsigned Index, ArrayRef ConformsTo) : SubstitutableType(TypeKind::DeducibleGenericParam, &Ctx, - /*Unresolved=*/false, ConformsTo), + /*Unresolved=*/true, ConformsTo), Name(Name), Index(Index) { } public: diff --git a/lib/Sema/TypeCheckCoercion.cpp b/lib/Sema/TypeCheckCoercion.cpp index 8794e6be7a7..a6101e2adf7 100644 --- a/lib/Sema/TypeCheckCoercion.cpp +++ b/lib/Sema/TypeCheckCoercion.cpp @@ -228,7 +228,18 @@ class SemaCoerce : public ExprVisitor { /// \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,