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