@@ -3068,11 +3068,15 @@ class ObjCImplementationChecker {
3068
3068
}
3069
3069
3070
3070
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 ());
3073
3073
return ObjCSelector ();
3074
3074
}
3075
3075
3076
+ static llvm::Optional<ObjCSelector> getObjCName (ValueDecl *VD) {
3077
+ return VD->getObjCRuntimeName ();
3078
+ }
3079
+
3076
3080
public:
3077
3081
void matchRequirements () {
3078
3082
// Try matching requirements with decreasing stringency.
@@ -3215,12 +3219,11 @@ class ObjCImplementationChecker {
3215
3219
for (auto req : matchedRequirements.matches ) {
3216
3220
auto diag =
3217
3221
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));
3220
3224
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 );
3224
3227
}
3225
3228
}
3226
3229
@@ -3257,19 +3260,18 @@ class ObjCImplementationChecker {
3257
3260
auto ext =
3258
3261
cast<ExtensionDecl>(reqIDC->getImplementationContext ());
3259
3262
diagnose (ext, diag::objc_implementation_multiple_matching_candidates,
3260
- req, *req-> getObjCRuntimeName ( ));
3263
+ req, *getObjCName (req ));
3261
3264
3262
3265
for (auto cand : cands.matches ) {
3263
3266
bool shouldOfferFix = !unmatchedCandidates[cand];
3264
3267
auto diag =
3265
3268
diagnose (cand, diag::objc_implementation_candidate_impl_here,
3266
3269
cand, shouldOfferFix,
3267
- req-> getObjCRuntimeName ( )->getString (scratch));
3270
+ getObjCName (req )->getString (scratch));
3268
3271
3269
3272
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 );
3273
3275
}
3274
3276
}
3275
3277
@@ -3362,8 +3364,7 @@ class ObjCImplementationChecker {
3362
3364
3363
3365
MatchOutcome matchesImpl (ValueDecl *req, ValueDecl *cand,
3364
3366
ObjCSelector explicitObjCName) const {
3365
- bool hasObjCNameMatch =
3366
- req->getObjCRuntimeName () == cand->getObjCRuntimeName ();
3367
+ bool hasObjCNameMatch = getObjCName (req) == getObjCName (cand);
3367
3368
bool hasSwiftNameMatch = areSwiftNamesEqual (req->getName (), cand->getName ());
3368
3369
3369
3370
// If neither the ObjC nor Swift names match, there's absolutely no reason
@@ -3373,8 +3374,7 @@ class ObjCImplementationChecker {
3373
3374
3374
3375
// There's at least some reason to treat these as matches.
3375
3376
3376
- if (explicitObjCName
3377
- && req->getObjCRuntimeName () != explicitObjCName)
3377
+ if (explicitObjCName && getObjCName (req) != explicitObjCName)
3378
3378
return MatchOutcome::WrongExplicitObjCName;
3379
3379
3380
3380
if (!hasSwiftNameMatch)
@@ -3430,7 +3430,7 @@ class ObjCImplementationChecker {
3430
3430
3431
3431
void diagnoseOutcome (MatchOutcome outcome, ValueDecl *req, ValueDecl *cand,
3432
3432
ObjCSelector explicitObjCName) {
3433
- auto reqObjCName = *req-> getObjCRuntimeName ( );
3433
+ auto reqObjCName = *getObjCName (req );
3434
3434
3435
3435
switch (outcome) {
3436
3436
case MatchOutcome::NoRelationship:
@@ -3447,7 +3447,7 @@ class ObjCImplementationChecker {
3447
3447
case MatchOutcome::WrongImplicitObjCName:
3448
3448
case MatchOutcome::WrongExplicitObjCName: {
3449
3449
auto diag = diagnose (cand, diag::objc_implementation_wrong_objc_name,
3450
- *cand-> getObjCRuntimeName ( ), cand, reqObjCName);
3450
+ *getObjCName (cand ), cand, reqObjCName);
3451
3451
fixDeclarationObjCName (diag, cand, explicitObjCName, reqObjCName);
3452
3452
return ;
3453
3453
}
@@ -3459,8 +3459,8 @@ class ObjCImplementationChecker {
3459
3459
if (!explicitObjCName) {
3460
3460
// Changing the Swift name will probably change the implicitly-computed
3461
3461
// 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 );
3464
3464
}
3465
3465
return ;
3466
3466
}
0 commit comments