@@ -3041,6 +3041,13 @@ matchFunctionThrowing(ConstraintSystem &cs,
30413041 }
30423042}
30433043
3044+ static bool isWitnessMatching(ConstraintLocatorBuilder locator) {
3045+ SmallVector<LocatorPathElt, 4> path;
3046+ (void) locator.getLocatorParts(path);
3047+ return (path.size() == 1 &&
3048+ path[0].is<LocatorPathElt::Witness>());
3049+ }
3050+
30443051bool
30453052ConstraintSystem::matchFunctionIsolations(FunctionType *func1,
30463053 FunctionType *func2,
@@ -3054,8 +3061,11 @@ ConstraintSystem::matchFunctionIsolations(FunctionType *func1,
30543061 // function-conversion score to make sure this solution is worse than
30553062 // an exact match.
30563063 // FIXME: there may be a better way. see https://github.com/apple/swift/pull/62514
3057- auto matchIfConversion = [&]() -> bool {
3058- if (kind < ConstraintKind::Subtype)
3064+ auto matchIfConversion = [&](bool isErasure = false) -> bool {
3065+ // We generally require a conversion here, but allow some lassitude
3066+ // if we're doing witness-matching.
3067+ if (kind < ConstraintKind::Subtype &&
3068+ !(isErasure && isWitnessMatching(locator)))
30593069 return false;
30603070 increaseScore(SK_FunctionConversion, locator);
30613071 return true;
@@ -3154,7 +3164,7 @@ ConstraintSystem::matchFunctionIsolations(FunctionType *func1,
31543164 // isolation as a conversion.
31553165 case FunctionTypeIsolation::Kind::NonIsolated:
31563166 case FunctionTypeIsolation::Kind::GlobalActor:
3157- return matchIfConversion();
3167+ return matchIfConversion(/*erasure*/ true );
31583168
31593169 // Parameter isolation is value-dependent and can't be erased in the
31603170 // abstract, though. We need to be able to recover the isolation from
@@ -5579,9 +5589,11 @@ bool ConstraintSystem::repairFailures(
55795589 }
55805590
55815591 if (auto *VD = getAsDecl<ValueDecl>(anchor)) {
5582- // Matching a witness to a ObjC protocol requirement.
5583- if (VD->isObjC() && VD->isProtocolRequirement() &&
5584- path[0].is<LocatorPathElt::Witness>() &&
5592+ // Matching a witness to an ObjC protocol requirement.
5593+ if (VD->isObjC() &&
5594+ isa<ProtocolDecl>(VD->getDeclContext()) &&
5595+ VD->isProtocolRequirement() &&
5596+ path[0].is<LocatorPathElt::Witness>() &&
55855597 // Note that the condition below is very important,
55865598 // we need to wait until the very last moment to strip
55875599 // the concurrency annotations from the inner most type.
@@ -5593,10 +5605,11 @@ bool ConstraintSystem::repairFailures(
55935605 if (!(Context.isSwiftVersionAtLeast(6) ||
55945606 Context.LangOpts.StrictConcurrencyLevel ==
55955607 StrictConcurrency::Complete)) {
5596- auto strippedLHS = lhs->stripConcurrency(/*resursive =*/true,
5608+ auto strippedLHS = lhs->stripConcurrency(/*recursive =*/true,
55975609 /*dropGlobalActor=*/true);
5598- auto strippedRHS = rhs->stripConcurrency(/*resursive =*/true,
5610+ auto strippedRHS = rhs->stripConcurrency(/*recursive =*/true,
55995611 /*dropGlobalActor=*/true);
5612+
56005613 auto result = matchTypes(strippedLHS, strippedRHS, matchKind,
56015614 flags | TMF_ApplyingFix, locator);
56025615 if (!result.isFailure()) {
0 commit comments