@@ -5466,47 +5466,7 @@ bool FailureDiagnosis::diagnoseSubscriptMisuse(ApplyExpr *callExpr) {
5466
5466
CalleeCandidateInfo candidateInfo (baseType, choices,
5467
5467
callArgHasTrailingClosure (argExpr),
5468
5468
CS, true );
5469
- struct TypeConvertibleChecker {
5470
- ConstraintSystem &CS;
5471
-
5472
- TypeConvertibleChecker (ConstraintSystem &CS) : CS(CS) {}
5473
5469
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);
5510
5470
auto params = swift::decomposeArgType (CS.getType (argExpr), argLabels);
5511
5471
using ClosenessPair = CalleeCandidateInfo::ClosenessResultTy;
5512
5472
@@ -5520,8 +5480,9 @@ bool FailureDiagnosis::diagnoseSubscriptMisuse(ApplyExpr *callExpr) {
5520
5480
return {CC_GeneralMismatch, {}};
5521
5481
5522
5482
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>())
5525
5486
continue ;
5526
5487
return {CC_GeneralMismatch, {}};
5527
5488
}
0 commit comments