Skip to content

Commit 51319ee

Browse files
authored
Merge pull request #17106 from AnthonyLatsis/clean_subscript_fixits_logic
[CSDiag] Remove nested type and use TC.isConvertible instead
2 parents dff379e + 88928a8 commit 51319ee

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
@@ -5466,47 +5466,7 @@ bool FailureDiagnosis::diagnoseSubscriptMisuse(ApplyExpr *callExpr) {
54665466
CalleeCandidateInfo candidateInfo(baseType, choices,
54675467
callArgHasTrailingClosure(argExpr),
54685468
CS, true);
5469-
struct TypeConvertibleChecker {
5470-
ConstraintSystem &CS;
5471-
5472-
TypeConvertibleChecker(ConstraintSystem &CS) : CS(CS) {}
54735469

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

@@ -5520,8 +5480,9 @@ bool FailureDiagnosis::diagnoseSubscriptMisuse(ApplyExpr *callExpr) {
55205480
return {CC_GeneralMismatch, {}};
55215481

55225482
for (unsigned i = 0, e = params.size(); i < e; i ++) {
5523-
if (checker.isImplicitlyConvertible(params[i].getType(),
5524-
candParams[i].getType()))
5483+
if (CS.TC.isConvertibleTo(params[i].getType(),
5484+
candParams[i].getType(), CS.DC) ||
5485+
candParams[i].getType()->is<GenericTypeParamType>())
55255486
continue;
55265487
return {CC_GeneralMismatch, {}};
55275488
}

0 commit comments

Comments
 (0)