mirror of
https://github.com/apple/swift.git
synced 2025-12-21 12:14:44 +01:00
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:
@@ -1235,7 +1235,7 @@ class DeducibleGenericParamType : public SubstitutableType {
|
|||||||
DeducibleGenericParamType(ASTContext &Ctx, Identifier Name, unsigned Index,
|
DeducibleGenericParamType(ASTContext &Ctx, Identifier Name, unsigned Index,
|
||||||
ArrayRef<ProtocolDecl *> ConformsTo)
|
ArrayRef<ProtocolDecl *> ConformsTo)
|
||||||
: SubstitutableType(TypeKind::DeducibleGenericParam, &Ctx,
|
: SubstitutableType(TypeKind::DeducibleGenericParam, &Ctx,
|
||||||
/*Unresolved=*/false, ConformsTo),
|
/*Unresolved=*/true, ConformsTo),
|
||||||
Name(Name), Index(Index) { }
|
Name(Name), Index(Index) { }
|
||||||
|
|
||||||
public:
|
public:
|
||||||
|
|||||||
@@ -229,6 +229,17 @@ class SemaCoerce : public ExprVisitor<SemaCoerce, CoercedResult> {
|
|||||||
/// \brief Try to perform a user-defined conversion.
|
/// \brief Try to perform a user-defined conversion.
|
||||||
CoercedResult tryUserConversion(Expr *E);
|
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:
|
public:
|
||||||
CoercedResult visitErrorExpr(ErrorExpr *E) {
|
CoercedResult visitErrorExpr(ErrorExpr *E) {
|
||||||
return unchanged(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
|
// Because we have coerced something in the source tuple, we need to
|
||||||
// rebuild the type of that tuple.
|
// rebuild the type of that tuple.
|
||||||
RebuildSourceType = true;
|
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?
|
// FIXME: Allow conversions when we don't have a tuple expression?
|
||||||
if (Flags & CF_Apply)
|
if (Flags & CF_Apply)
|
||||||
TC.diagnose(E->getLoc(), diag::tuple_element_type_mismatch, SrcField,
|
TC.diagnose(E->getLoc(), diag::tuple_element_type_mismatch, SrcField,
|
||||||
|
|||||||
Reference in New Issue
Block a user