@@ -2372,12 +2372,22 @@ bool swift::diagnoseObjCUnsatisfiedOptReqConflicts(SourceFile &sf) {
2372
2372
if (conflicts.empty ())
2373
2373
continue ;
2374
2374
2375
+ auto bestConflict = conflicts[0 ];
2376
+ for (auto conflict : conflicts) {
2377
+ if (conflict->getName ().isCompoundName () &&
2378
+ conflict->getName ().getArgumentNames ().size () ==
2379
+ req->getName ().getArgumentNames ().size ()) {
2380
+ bestConflict = conflict;
2381
+ break ;
2382
+ }
2383
+ }
2384
+
2375
2385
// Diagnose the conflict.
2376
2386
auto reqDiagInfo = getObjCMethodDiagInfo (unsatisfied.second );
2377
- auto conflictDiagInfo = getObjCMethodDiagInfo (conflicts[ 0 ] );
2387
+ auto conflictDiagInfo = getObjCMethodDiagInfo (bestConflict );
2378
2388
auto protocolName
2379
2389
= cast<ProtocolDecl>(req->getDeclContext ())->getName ();
2380
- Ctx.Diags .diagnose (conflicts[ 0 ] ,
2390
+ Ctx.Diags .diagnose (bestConflict ,
2381
2391
diag::objc_optional_requirement_conflict,
2382
2392
conflictDiagInfo.first ,
2383
2393
conflictDiagInfo.second ,
@@ -2387,9 +2397,9 @@ bool swift::diagnoseObjCUnsatisfiedOptReqConflicts(SourceFile &sf) {
2387
2397
protocolName);
2388
2398
2389
2399
// Fix the name of the witness, if we can.
2390
- if (req->getName () != conflicts[ 0 ] ->getName () &&
2391
- req->getKind () == conflicts[ 0 ] ->getKind () &&
2392
- isa<AccessorDecl>(req) == isa<AccessorDecl>(conflicts[ 0 ] )) {
2400
+ if (req->getName () != bestConflict ->getName () &&
2401
+ req->getKind () == bestConflict ->getKind () &&
2402
+ isa<AccessorDecl>(req) == isa<AccessorDecl>(bestConflict )) {
2393
2403
// They're of the same kind: fix the name.
2394
2404
unsigned kind;
2395
2405
if (isa<ConstructorDecl>(req))
@@ -2402,29 +2412,29 @@ bool swift::diagnoseObjCUnsatisfiedOptReqConflicts(SourceFile &sf) {
2402
2412
llvm_unreachable (" unhandled @objc declaration kind" );
2403
2413
}
2404
2414
2405
- auto diag = Ctx.Diags .diagnose (conflicts[ 0 ] ,
2415
+ auto diag = Ctx.Diags .diagnose (bestConflict ,
2406
2416
diag::objc_optional_requirement_swift_rename,
2407
2417
kind, req->getName ());
2408
2418
2409
2419
// Fix the Swift name.
2410
- fixDeclarationName (diag, conflicts[ 0 ] , req->getName ());
2420
+ fixDeclarationName (diag, bestConflict , req->getName ());
2411
2421
2412
2422
// Fix the '@objc' attribute, if needed.
2413
- if (!conflicts[ 0 ] ->canInferObjCFromRequirement (req))
2414
- fixDeclarationObjCName (diag, conflicts[ 0 ] ,
2415
- conflicts[ 0 ] ->getObjCRuntimeName (),
2423
+ if (!bestConflict ->canInferObjCFromRequirement (req))
2424
+ fixDeclarationObjCName (diag, bestConflict ,
2425
+ bestConflict ->getObjCRuntimeName (),
2416
2426
req->getObjCRuntimeName (),
2417
2427
/* ignoreImpliedName=*/ true );
2418
2428
}
2419
2429
2420
2430
// @nonobjc will silence this warning.
2421
2431
bool hasExplicitObjCAttribute = false ;
2422
- if (auto objcAttr = conflicts[ 0 ] ->getAttrs ().getAttribute <ObjCAttr>())
2432
+ if (auto objcAttr = bestConflict ->getAttrs ().getAttribute <ObjCAttr>())
2423
2433
hasExplicitObjCAttribute = !objcAttr->isImplicit ();
2424
2434
if (!hasExplicitObjCAttribute)
2425
- Ctx.Diags .diagnose (conflicts[ 0 ] , diag::req_near_match_nonobjc, true )
2435
+ Ctx.Diags .diagnose (bestConflict , diag::req_near_match_nonobjc, true )
2426
2436
.fixItInsert (
2427
- conflicts[ 0 ] ->getAttributeInsertionLoc (/* forModifier=*/ false ),
2437
+ bestConflict ->getAttributeInsertionLoc (/* forModifier=*/ false ),
2428
2438
" @nonobjc " );
2429
2439
2430
2440
Ctx.Diags .diagnose (getDeclContextLoc (unsatisfied.first ),
0 commit comments