@@ -3068,11 +3068,15 @@ class ObjCImplementationChecker {
30683068 }
30693069
30703070 static ObjCSelector getExplicitObjCName (ValueDecl *VD) {
3071- if (auto attr = VD->getAttrs ().getAttribute <ObjCAttr>())
3072- return attr ->getName ().value_or (ObjCSelector ());
3071+ if (auto objcAttr = VD->getAttrs ().getAttribute <ObjCAttr>())
3072+ return objcAttr ->getName ().value_or (ObjCSelector ());
30733073 return ObjCSelector ();
30743074 }
30753075
3076+ static llvm::Optional<ObjCSelector> getObjCName (ValueDecl *VD) {
3077+ return VD->getObjCRuntimeName ();
3078+ }
3079+
30763080public:
30773081 void matchRequirements () {
30783082 // Try matching requirements with decreasing stringency.
@@ -3215,12 +3219,11 @@ class ObjCImplementationChecker {
32153219 for (auto req : matchedRequirements.matches ) {
32163220 auto diag =
32173221 diagnose (cand, diag::objc_implementation_one_matched_requirement,
3218- req, *req-> getObjCRuntimeName ( ), shouldOfferFix,
3219- req-> getObjCRuntimeName ( )->getString (scratch));
3222+ req, *getObjCName (req ), shouldOfferFix,
3223+ getObjCName (req )->getString (scratch));
32203224 if (shouldOfferFix) {
3221- fixDeclarationObjCName (diag, cand, cand->getObjCRuntimeName (),
3222- req->getObjCRuntimeName (),
3223- /* ignoreImpliedName=*/ true );
3225+ fixDeclarationObjCName (diag, cand, getObjCName (cand),
3226+ getObjCName (req), /* ignoreImpliedName=*/ true );
32243227 }
32253228 }
32263229
@@ -3257,19 +3260,18 @@ class ObjCImplementationChecker {
32573260 auto ext =
32583261 cast<ExtensionDecl>(reqIDC->getImplementationContext ());
32593262 diagnose (ext, diag::objc_implementation_multiple_matching_candidates,
3260- req, *req-> getObjCRuntimeName ( ));
3263+ req, *getObjCName (req ));
32613264
32623265 for (auto cand : cands.matches ) {
32633266 bool shouldOfferFix = !unmatchedCandidates[cand];
32643267 auto diag =
32653268 diagnose (cand, diag::objc_implementation_candidate_impl_here,
32663269 cand, shouldOfferFix,
3267- req-> getObjCRuntimeName ( )->getString (scratch));
3270+ getObjCName (req )->getString (scratch));
32683271
32693272 if (shouldOfferFix) {
3270- fixDeclarationObjCName (diag, cand, cand->getObjCRuntimeName (),
3271- req->getObjCRuntimeName (),
3272- /* ignoreImpliedName=*/ true );
3273+ fixDeclarationObjCName (diag, cand, getObjCName (cand),
3274+ getObjCName (req), /* ignoreImpliedName=*/ true );
32733275 }
32743276 }
32753277
@@ -3362,8 +3364,7 @@ class ObjCImplementationChecker {
33623364
33633365 MatchOutcome matchesImpl (ValueDecl *req, ValueDecl *cand,
33643366 ObjCSelector explicitObjCName) const {
3365- bool hasObjCNameMatch =
3366- req->getObjCRuntimeName () == cand->getObjCRuntimeName ();
3367+ bool hasObjCNameMatch = getObjCName (req) == getObjCName (cand);
33673368 bool hasSwiftNameMatch = areSwiftNamesEqual (req->getName (), cand->getName ());
33683369
33693370 // If neither the ObjC nor Swift names match, there's absolutely no reason
@@ -3373,8 +3374,7 @@ class ObjCImplementationChecker {
33733374
33743375 // There's at least some reason to treat these as matches.
33753376
3376- if (explicitObjCName
3377- && req->getObjCRuntimeName () != explicitObjCName)
3377+ if (explicitObjCName && getObjCName (req) != explicitObjCName)
33783378 return MatchOutcome::WrongExplicitObjCName;
33793379
33803380 if (!hasSwiftNameMatch)
@@ -3430,7 +3430,7 @@ class ObjCImplementationChecker {
34303430
34313431 void diagnoseOutcome (MatchOutcome outcome, ValueDecl *req, ValueDecl *cand,
34323432 ObjCSelector explicitObjCName) {
3433- auto reqObjCName = *req-> getObjCRuntimeName ( );
3433+ auto reqObjCName = *getObjCName (req );
34343434
34353435 switch (outcome) {
34363436 case MatchOutcome::NoRelationship:
@@ -3447,7 +3447,7 @@ class ObjCImplementationChecker {
34473447 case MatchOutcome::WrongImplicitObjCName:
34483448 case MatchOutcome::WrongExplicitObjCName: {
34493449 auto diag = diagnose (cand, diag::objc_implementation_wrong_objc_name,
3450- *cand-> getObjCRuntimeName ( ), cand, reqObjCName);
3450+ *getObjCName (cand ), cand, reqObjCName);
34513451 fixDeclarationObjCName (diag, cand, explicitObjCName, reqObjCName);
34523452 return ;
34533453 }
@@ -3459,8 +3459,8 @@ class ObjCImplementationChecker {
34593459 if (!explicitObjCName) {
34603460 // Changing the Swift name will probably change the implicitly-computed
34613461 // ObjC name, so let's make that explicit.
3462- fixDeclarationObjCName (diag, cand, cand-> getObjCRuntimeName () ,
3463- reqObjCName, /* ignoreImpliedName=*/ true );
3462+ fixDeclarationObjCName (diag, cand, getObjCName (cand), reqObjCName ,
3463+ /* ignoreImpliedName=*/ true );
34643464 }
34653465 return ;
34663466 }
0 commit comments