@@ -1026,7 +1026,6 @@ swift::matchWitness(WitnessChecker::RequirementEnvironmentCache &reqEnvCache,
10261026
10271027 // Initialized by the setup operation.
10281028 std::optional<ConstraintSystem> cs;
1029- ConstraintLocator *locator = nullptr ;
10301029 ConstraintLocator *reqLocator = nullptr ;
10311030 ConstraintLocator *witnessLocator = nullptr ;
10321031 Type witnessType, openWitnessType;
@@ -1115,8 +1114,8 @@ swift::matchWitness(WitnessChecker::RequirementEnvironmentCache &reqEnvCache,
11151114 selfTy = syntheticEnv->mapTypeIntoContext (selfTy);
11161115
11171116 // Open up the type of the requirement.
1118- reqLocator = cs-> getConstraintLocator (
1119- static_cast <Expr *>( nullptr ), LocatorPathElt ::ProtocolRequirement(req) );
1117+ reqLocator =
1118+ cs-> getConstraintLocator (req, ConstraintLocator ::ProtocolRequirement);
11201119 OpenedTypeMap reqReplacements;
11211120 reqType = cs->getTypeOfMemberReference (selfTy, req, dc,
11221121 /* isDynamicResult=*/ false ,
@@ -1151,10 +1150,8 @@ swift::matchWitness(WitnessChecker::RequirementEnvironmentCache &reqEnvCache,
11511150
11521151 // Open up the witness type.
11531152 witnessType = witness->getInterfaceType ();
1154- // FIXME: witness as a base locator?
1155- locator = cs->getConstraintLocator ({});
1156- witnessLocator = cs->getConstraintLocator ({},
1157- LocatorPathElt::Witness (witness));
1153+ witnessLocator =
1154+ cs->getConstraintLocator (req, LocatorPathElt::Witness (witness));
11581155 if (witness->getDeclContext ()->isTypeContext ()) {
11591156 openWitnessType = cs->getTypeOfMemberReference (
11601157 selfTy, witness, dc, /* isDynamicResult=*/ false ,
@@ -1174,44 +1171,8 @@ swift::matchWitness(WitnessChecker::RequirementEnvironmentCache &reqEnvCache,
11741171 // Match a type in the requirement to a type in the witness.
11751172 auto matchTypes = [&](Type reqType,
11761173 Type witnessType) -> std::optional<RequirementMatch> {
1177- // `swift_attr` attributes in the type context were ignored before,
1178- // which means that we need to maintain status quo to avoid breaking
1179- // witness matching by stripping everything concurrency related from
1180- // inner types.
1181- auto shouldStripConcurrency = [&]() {
1182- if (!req->isObjC ())
1183- return false ;
1184-
1185- auto &ctx = dc->getASTContext ();
1186- return !(ctx.isSwiftVersionAtLeast (6 ) ||
1187- ctx.LangOpts .StrictConcurrencyLevel ==
1188- StrictConcurrency::Complete);
1189- };
1190-
1191- if (shouldStripConcurrency ()) {
1192- if (reqType->is <FunctionType>()) {
1193- auto *fnTy = reqType->castTo <FunctionType>();
1194- SmallVector<AnyFunctionType::Param, 4 > params;
1195- llvm::transform (fnTy->getParams (), std::back_inserter (params),
1196- [&](const AnyFunctionType::Param ¶m) {
1197- return param.withType (
1198- param.getPlainType ()->stripConcurrency (
1199- /* recursive=*/ true ,
1200- /* dropGlobalActor=*/ true ));
1201- });
1202-
1203- auto resultTy =
1204- fnTy->getResult ()->stripConcurrency (/* recursive=*/ true ,
1205- /* dropGlobalActor=*/ true );
1206-
1207- reqType = FunctionType::get (params, resultTy, fnTy->getExtInfo ());
1208- } else {
1209- reqType = reqType->stripConcurrency (/* recursive=*/ true ,
1210- /* dropGlobalActor=*/ true );
1211- }
1212- }
1213-
1214- cs->addConstraint (ConstraintKind::Bind, reqType, witnessType, locator);
1174+ cs->addConstraint (ConstraintKind::Bind, reqType, witnessType,
1175+ witnessLocator);
12151176 // FIXME: Check whether this has already failed.
12161177 return std::nullopt ;
12171178 };
@@ -1235,14 +1196,31 @@ swift::matchWitness(WitnessChecker::RequirementEnvironmentCache &reqEnvCache,
12351196 return *result;
12361197 }
12371198 }
1238- bool requiresNonSendable = false ;
1239- if (!solution || solution->Fixes .size ()) {
1240- // / If the *only* problems are that `@Sendable` attributes are missing,
1241- // / allow the match in some circumstances.
1242- requiresNonSendable = solution
1243- && llvm::all_of (solution->Fixes , [](constraints::ConstraintFix *fix) {
1244- return fix->getKind () == constraints::FixKind::AddSendableAttribute;
1245- });
1199+
1200+ bool requiresNonSendable = [&]() {
1201+ if (!solution)
1202+ return false ;
1203+
1204+ // If the *only* problems are that `@Sendable` attributes are missing,
1205+ // allow the match in some circumstances.
1206+ if (!solution->Fixes .empty ()) {
1207+ return llvm::all_of (solution->Fixes ,
1208+ [](constraints::ConstraintFix *fix) {
1209+ return fix->getKind () ==
1210+ constraints::FixKind::AddSendableAttribute;
1211+ });
1212+ }
1213+
1214+ // If there are no other issues, let's check whether this are
1215+ // missing Sendable conformances when matching ObjC requirements.
1216+ // This is not an error until Swift 6 because `swift_attr` wasn't
1217+ // allowed in type contexts initially.
1218+ return req->isObjC () &&
1219+ solution->getFixedScore ()
1220+ .Data [SK_MissingSynthesizableConformance] > 0 ;
1221+ }();
1222+
1223+ if (!solution || !solution->Fixes .empty ()) {
12461224 if (!requiresNonSendable)
12471225 return RequirementMatch (witness, MatchKind::TypeConflict,
12481226 witnessType);
0 commit comments