@@ -5474,47 +5474,7 @@ bool FailureDiagnosis::diagnoseSubscriptMisuse(ApplyExpr *callExpr) {
5474
5474
CalleeCandidateInfo candidateInfo (baseType, choices,
5475
5475
callArgHasTrailingClosure (argExpr),
5476
5476
CS, true );
5477
- struct TypeConvertibleChecker {
5478
- ConstraintSystem &CS;
5479
-
5480
- TypeConvertibleChecker (ConstraintSystem &CS) : CS(CS) {}
5481
5477
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);
5518
5478
auto params = swift::decomposeArgType (CS.getType (argExpr), argLabels);
5519
5479
using ClosenessPair = CalleeCandidateInfo::ClosenessResultTy;
5520
5480
@@ -5528,8 +5488,9 @@ bool FailureDiagnosis::diagnoseSubscriptMisuse(ApplyExpr *callExpr) {
5528
5488
return {CC_GeneralMismatch, {}};
5529
5489
5530
5490
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>())
5533
5494
continue ;
5534
5495
return {CC_GeneralMismatch, {}};
5535
5496
}
0 commit comments