@@ -3041,6 +3041,13 @@ matchFunctionThrowing(ConstraintSystem &cs,
3041
3041
}
3042
3042
}
3043
3043
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
+
3044
3051
bool
3045
3052
ConstraintSystem::matchFunctionIsolations(FunctionType *func1,
3046
3053
FunctionType *func2,
@@ -3054,8 +3061,11 @@ ConstraintSystem::matchFunctionIsolations(FunctionType *func1,
3054
3061
// function-conversion score to make sure this solution is worse than
3055
3062
// an exact match.
3056
3063
// 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)))
3059
3069
return false;
3060
3070
increaseScore(SK_FunctionConversion, locator);
3061
3071
return true;
@@ -3154,7 +3164,7 @@ ConstraintSystem::matchFunctionIsolations(FunctionType *func1,
3154
3164
// isolation as a conversion.
3155
3165
case FunctionTypeIsolation::Kind::NonIsolated:
3156
3166
case FunctionTypeIsolation::Kind::GlobalActor:
3157
- return matchIfConversion();
3167
+ return matchIfConversion(/*erasure*/ true );
3158
3168
3159
3169
// Parameter isolation is value-dependent and can't be erased in the
3160
3170
// abstract, though. We need to be able to recover the isolation from
@@ -5579,9 +5589,11 @@ bool ConstraintSystem::repairFailures(
5579
5589
}
5580
5590
5581
5591
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>() &&
5585
5597
// Note that the condition below is very important,
5586
5598
// we need to wait until the very last moment to strip
5587
5599
// the concurrency annotations from the inner most type.
@@ -5593,10 +5605,11 @@ bool ConstraintSystem::repairFailures(
5593
5605
if (!(Context.isSwiftVersionAtLeast(6) ||
5594
5606
Context.LangOpts.StrictConcurrencyLevel ==
5595
5607
StrictConcurrency::Complete)) {
5596
- auto strippedLHS = lhs->stripConcurrency(/*resursive =*/true,
5608
+ auto strippedLHS = lhs->stripConcurrency(/*recursive =*/true,
5597
5609
/*dropGlobalActor=*/true);
5598
- auto strippedRHS = rhs->stripConcurrency(/*resursive =*/true,
5610
+ auto strippedRHS = rhs->stripConcurrency(/*recursive =*/true,
5599
5611
/*dropGlobalActor=*/true);
5612
+
5600
5613
auto result = matchTypes(strippedLHS, strippedRHS, matchKind,
5601
5614
flags | TMF_ApplyingFix, locator);
5602
5615
if (!result.isFailure()) {
0 commit comments