@@ -1748,7 +1748,7 @@ static ObjCSelector inferObjCName(ValueDecl *decl) {
1748
1748
diag::objc_override_method_selector_mismatch,
1749
1749
*attr->getName (), overriddenSelector)
1750
1750
.limitBehavior (behavior));
1751
- fixDeclarationObjCName (diag, decl, attr->getName (),
1751
+ fixDeclarationObjCName (diag, decl, attr->getName (). value () ,
1752
1752
overriddenSelector);
1753
1753
}
1754
1754
@@ -1838,8 +1838,9 @@ static ObjCSelector inferObjCName(ValueDecl *decl) {
1838
1838
auto diag = decl->diagnose (diag::objc_ambiguous_inference_candidate,
1839
1839
req, proto, *req->getObjCRuntimeName ());
1840
1840
fixDeclarationObjCName (diag, decl,
1841
- decl->getObjCRuntimeName (/* skipIsObjC=*/ true ),
1842
- req->getObjCRuntimeName ());
1841
+ decl->getObjCRuntimeName (/* skipIsObjC=*/ true )
1842
+ .value_or (ObjCSelector ()),
1843
+ req->getObjCRuntimeName ().value ());
1843
1844
};
1844
1845
diagnoseCandidate (firstReq);
1845
1846
diagnoseCandidate (req);
@@ -2150,8 +2151,8 @@ bool swift::fixDeclarationName(InFlightDiagnostic &diag, const ValueDecl *decl,
2150
2151
2151
2152
bool swift::fixDeclarationObjCName (InFlightDiagnostic &diag,
2152
2153
const Decl *decl,
2153
- std::optional< ObjCSelector> nameOpt ,
2154
- std::optional< ObjCSelector> targetNameOpt ,
2154
+ ObjCSelector name ,
2155
+ ObjCSelector targetName ,
2155
2156
bool ignoreImpliedName) {
2156
2157
if (decl->isImplicit ())
2157
2158
return false ;
@@ -2163,9 +2164,6 @@ bool swift::fixDeclarationObjCName(InFlightDiagnostic &diag,
2163
2164
return false ;
2164
2165
}
2165
2166
2166
- auto name = *nameOpt;
2167
- auto targetName = *targetNameOpt;
2168
-
2169
2167
// Dig out the existing '@objc' attribute on the witness. We don't care
2170
2168
// about implicit ones because they don't have useful source location
2171
2169
// information.
@@ -2212,7 +2210,7 @@ bool swift::fixDeclarationObjCName(InFlightDiagnostic &diag,
2212
2210
2213
2211
// If the names of the witness and requirement differ, we need to
2214
2212
// specify the name.
2215
- if (name != targetName || ignoreImpliedName) {
2213
+ if (targetName && ( name != targetName || ignoreImpliedName) ) {
2216
2214
out << " (" ;
2217
2215
out << targetName;
2218
2216
out << " )" ;
@@ -2907,8 +2905,10 @@ bool swift::diagnoseObjCUnsatisfiedOptReqConflicts(SourceFile &sf) {
2907
2905
// Fix the '@objc' attribute, if needed.
2908
2906
if (!bestConflict->canInferObjCFromRequirement (req))
2909
2907
fixDeclarationObjCName (diag, bestConflict,
2910
- bestConflict->getObjCRuntimeName (),
2911
- req->getObjCRuntimeName (),
2908
+ bestConflict->getObjCRuntimeName ()
2909
+ .value_or (ObjCSelector ()),
2910
+ req->getObjCRuntimeName ()
2911
+ .value_or (ObjCSelector ()),
2912
2912
/* ignoreImpliedName=*/ true );
2913
2913
}
2914
2914
@@ -3277,12 +3277,12 @@ class ObjCImplementationChecker {
3277
3277
return ObjCSelector ();
3278
3278
}
3279
3279
3280
- static std::optional< ObjCSelector> getObjCName (ValueDecl *VD) {
3280
+ static ObjCSelector getObjCName (ValueDecl *VD) {
3281
3281
if (!VD->getCDeclName ().empty ()) {
3282
3282
auto ident = VD->getASTContext ().getIdentifier (VD->getCDeclName ());
3283
3283
return ObjCSelector (VD->getASTContext (), 0 , { ident });
3284
3284
}
3285
- return VD->getObjCRuntimeName ();
3285
+ return VD->getObjCRuntimeName (). value_or ( ObjCSelector ()) ;
3286
3286
}
3287
3287
3288
3288
public:
@@ -3427,8 +3427,8 @@ class ObjCImplementationChecker {
3427
3427
for (auto req : matchedRequirements.matches ) {
3428
3428
auto diag =
3429
3429
diagnose (cand, diag::objc_implementation_one_matched_requirement,
3430
- req, * getObjCName (req), shouldOfferFix,
3431
- getObjCName (req)-> getString (scratch));
3430
+ req, getObjCName (req), shouldOfferFix,
3431
+ getObjCName (req). getString (scratch));
3432
3432
if (shouldOfferFix) {
3433
3433
fixDeclarationObjCName (diag, cand, getObjCName (cand),
3434
3434
getObjCName (req), /* ignoreImpliedName=*/ true );
@@ -3468,14 +3468,14 @@ class ObjCImplementationChecker {
3468
3468
auto ext =
3469
3469
cast<ExtensionDecl>(reqIDC->getImplementationContext ());
3470
3470
diagnose (ext, diag::objc_implementation_multiple_matching_candidates,
3471
- req, * getObjCName (req));
3471
+ req, getObjCName (req));
3472
3472
3473
3473
for (auto cand : cands.matches ) {
3474
3474
bool shouldOfferFix = !unmatchedCandidates[cand];
3475
3475
auto diag =
3476
3476
diagnose (cand, diag::objc_implementation_candidate_impl_here,
3477
3477
cand, shouldOfferFix,
3478
- getObjCName (req)-> getString (scratch));
3478
+ getObjCName (req). getString (scratch));
3479
3479
3480
3480
if (shouldOfferFix) {
3481
3481
fixDeclarationObjCName (diag, cand, getObjCName (cand),
@@ -3650,7 +3650,7 @@ class ObjCImplementationChecker {
3650
3650
3651
3651
void diagnoseOutcome (MatchOutcome outcome, ValueDecl *req, ValueDecl *cand,
3652
3652
ObjCSelector explicitObjCName) {
3653
- auto reqObjCName = * getObjCName (req);
3653
+ auto reqObjCName = getObjCName (req);
3654
3654
3655
3655
switch (outcome) {
3656
3656
case MatchOutcome::NoRelationship:
@@ -3667,7 +3667,7 @@ class ObjCImplementationChecker {
3667
3667
case MatchOutcome::WrongImplicitObjCName:
3668
3668
case MatchOutcome::WrongExplicitObjCName: {
3669
3669
auto diag = diagnose (cand, diag::objc_implementation_wrong_objc_name,
3670
- * getObjCName (cand), cand, reqObjCName);
3670
+ getObjCName (cand), cand, reqObjCName);
3671
3671
fixDeclarationObjCName (diag, cand, explicitObjCName, reqObjCName);
3672
3672
return ;
3673
3673
}
0 commit comments