Skip to content

Commit 88928a8

Browse files
committed
[CSDiag] Remove nested type and use TC.isConvertible instead
1 parent cd5acad commit 88928a8

File tree

1 file changed

+3
-42
lines changed

1 file changed

+3
-42
lines changed

lib/Sema/CSDiag.cpp

Lines changed: 3 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -5474,47 +5474,7 @@ bool FailureDiagnosis::diagnoseSubscriptMisuse(ApplyExpr *callExpr) {
54745474
CalleeCandidateInfo candidateInfo(baseType, choices,
54755475
callArgHasTrailingClosure(argExpr),
54765476
CS, true);
5477-
struct TypeConvertibleChecker {
5478-
ConstraintSystem &CS;
5479-
5480-
TypeConvertibleChecker(ConstraintSystem &CS) : CS(CS) {}
54815477

5482-
// Checks whether type1 is implicitly convertible to type2
5483-
bool isImplicitlyConvertible(Type type1, Type type2) {
5484-
if (!type1 || !type2)
5485-
return false;
5486-
5487-
if (auto tup1 = type1->getAs<TupleType>()) {
5488-
if (auto tup2 = type2->getAs<TupleType>())
5489-
return isImplicitlyConvertibleTuple(tup1, tup2);
5490-
else
5491-
return false;
5492-
}
5493-
if (type1->isEqual(type2) || type2->is<GenericTypeParamType>() ||
5494-
CS.TC.isSubtypeOf(type1, type2, CS.DC))
5495-
return true;
5496-
return false;
5497-
}
5498-
5499-
bool isImplicitlyConvertibleTuple(TupleType *tup1, TupleType *tup2) {
5500-
if (tup1->getNumElements() != tup2->getNumElements())
5501-
return false;
5502-
5503-
for (unsigned i = 0, e = tup1->getNumElements(); i < e; i ++) {
5504-
auto element1 = tup1->getElement(i);
5505-
auto element2 = tup2->getElement(i);
5506-
if (element1.hasName()) {
5507-
if (!element2.hasName() || element1.getName() !=
5508-
element2.getName())
5509-
return false;
5510-
}
5511-
if (!isImplicitlyConvertible(element1.getType(),
5512-
element2.getType()))
5513-
return false;
5514-
}
5515-
return true;
5516-
}
5517-
} checker(CS);
55185478
auto params = swift::decomposeArgType(CS.getType(argExpr), argLabels);
55195479
using ClosenessPair = CalleeCandidateInfo::ClosenessResultTy;
55205480

@@ -5528,8 +5488,9 @@ bool FailureDiagnosis::diagnoseSubscriptMisuse(ApplyExpr *callExpr) {
55285488
return {CC_GeneralMismatch, {}};
55295489

55305490
for (unsigned i = 0, e = params.size(); i < e; i ++) {
5531-
if (checker.isImplicitlyConvertible(params[i].getType(),
5532-
candParams[i].getType()))
5491+
if (CS.TC.isConvertibleTo(params[i].getType(),
5492+
candParams[i].getType(), CS.DC) ||
5493+
candParams[i].getType()->is<GenericTypeParamType>())
55335494
continue;
55345495
return {CC_GeneralMismatch, {}};
55355496
}

0 commit comments

Comments
 (0)