@@ -1749,7 +1749,7 @@ static ObjCSelector inferObjCName(ValueDecl *decl) {
17491749 diag::objc_override_method_selector_mismatch,
17501750 *attr->getName (), overriddenSelector)
17511751 .limitBehavior (behavior));
1752- fixDeclarationObjCName (diag, decl, attr->getName (),
1752+ fixDeclarationObjCName (diag, decl, attr->getName (). value () ,
17531753 overriddenSelector);
17541754 }
17551755
@@ -1839,8 +1839,9 @@ static ObjCSelector inferObjCName(ValueDecl *decl) {
18391839 auto diag = decl->diagnose (diag::objc_ambiguous_inference_candidate,
18401840 req, proto, *req->getObjCRuntimeName ());
18411841 fixDeclarationObjCName (diag, decl,
1842- decl->getObjCRuntimeName (/* skipIsObjC=*/ true ),
1843- req->getObjCRuntimeName ());
1842+ decl->getObjCRuntimeName (/* skipIsObjC=*/ true )
1843+ .value_or (ObjCSelector ()),
1844+ req->getObjCRuntimeName ().value ());
18441845 };
18451846 diagnoseCandidate (firstReq);
18461847 diagnoseCandidate (req);
@@ -2151,8 +2152,8 @@ bool swift::fixDeclarationName(InFlightDiagnostic &diag, const ValueDecl *decl,
21512152
21522153bool swift::fixDeclarationObjCName (InFlightDiagnostic &diag,
21532154 const Decl *decl,
2154- std::optional< ObjCSelector> nameOpt ,
2155- std::optional< ObjCSelector> targetNameOpt ,
2155+ ObjCSelector name ,
2156+ ObjCSelector targetName ,
21562157 bool ignoreImpliedName) {
21572158 if (decl->isImplicit ())
21582159 return false ;
@@ -2164,9 +2165,6 @@ bool swift::fixDeclarationObjCName(InFlightDiagnostic &diag,
21642165 return false ;
21652166 }
21662167
2167- auto name = *nameOpt;
2168- auto targetName = *targetNameOpt;
2169-
21702168 // Dig out the existing '@objc' attribute on the witness. We don't care
21712169 // about implicit ones because they don't have useful source location
21722170 // information.
@@ -2213,7 +2211,7 @@ bool swift::fixDeclarationObjCName(InFlightDiagnostic &diag,
22132211
22142212 // If the names of the witness and requirement differ, we need to
22152213 // specify the name.
2216- if (name != targetName || ignoreImpliedName) {
2214+ if (targetName && ( name != targetName || ignoreImpliedName) ) {
22172215 out << " (" ;
22182216 out << targetName;
22192217 out << " )" ;
@@ -2908,8 +2906,10 @@ bool swift::diagnoseObjCUnsatisfiedOptReqConflicts(SourceFile &sf) {
29082906 // Fix the '@objc' attribute, if needed.
29092907 if (!bestConflict->canInferObjCFromRequirement (req))
29102908 fixDeclarationObjCName (diag, bestConflict,
2911- bestConflict->getObjCRuntimeName (),
2912- req->getObjCRuntimeName (),
2909+ bestConflict->getObjCRuntimeName ()
2910+ .value_or (ObjCSelector ()),
2911+ req->getObjCRuntimeName ()
2912+ .value_or (ObjCSelector ()),
29132913 /* ignoreImpliedName=*/ true );
29142914 }
29152915
@@ -3278,12 +3278,12 @@ class ObjCImplementationChecker {
32783278 return ObjCSelector ();
32793279 }
32803280
3281- static std::optional< ObjCSelector> getObjCName (ValueDecl *VD) {
3281+ static ObjCSelector getObjCName (ValueDecl *VD) {
32823282 if (!VD->getCDeclName ().empty ()) {
32833283 auto ident = VD->getASTContext ().getIdentifier (VD->getCDeclName ());
32843284 return ObjCSelector (VD->getASTContext (), 0 , { ident });
32853285 }
3286- return VD->getObjCRuntimeName ();
3286+ return VD->getObjCRuntimeName (). value_or ( ObjCSelector ()) ;
32873287 }
32883288
32893289public:
@@ -3428,8 +3428,8 @@ class ObjCImplementationChecker {
34283428 for (auto req : matchedRequirements.matches ) {
34293429 auto diag =
34303430 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));
34333433 if (shouldOfferFix) {
34343434 fixDeclarationObjCName (diag, cand, getObjCName (cand),
34353435 getObjCName (req), /* ignoreImpliedName=*/ true );
@@ -3469,14 +3469,14 @@ class ObjCImplementationChecker {
34693469 auto ext =
34703470 cast<ExtensionDecl>(reqIDC->getImplementationContext ());
34713471 diagnose (ext, diag::objc_implementation_multiple_matching_candidates,
3472- req, * getObjCName (req));
3472+ req, getObjCName (req));
34733473
34743474 for (auto cand : cands.matches ) {
34753475 bool shouldOfferFix = !unmatchedCandidates[cand];
34763476 auto diag =
34773477 diagnose (cand, diag::objc_implementation_candidate_impl_here,
34783478 cand, shouldOfferFix,
3479- getObjCName (req)-> getString (scratch));
3479+ getObjCName (req). getString (scratch));
34803480
34813481 if (shouldOfferFix) {
34823482 fixDeclarationObjCName (diag, cand, getObjCName (cand),
@@ -3651,7 +3651,7 @@ class ObjCImplementationChecker {
36513651
36523652 void diagnoseOutcome (MatchOutcome outcome, ValueDecl *req, ValueDecl *cand,
36533653 ObjCSelector explicitObjCName) {
3654- auto reqObjCName = * getObjCName (req);
3654+ auto reqObjCName = getObjCName (req);
36553655
36563656 switch (outcome) {
36573657 case MatchOutcome::NoRelationship:
@@ -3668,7 +3668,7 @@ class ObjCImplementationChecker {
36683668 case MatchOutcome::WrongImplicitObjCName:
36693669 case MatchOutcome::WrongExplicitObjCName: {
36703670 auto diag = diagnose (cand, diag::objc_implementation_wrong_objc_name,
3671- * getObjCName (cand), cand, reqObjCName);
3671+ getObjCName (cand), cand, reqObjCName);
36723672 fixDeclarationObjCName (diag, cand, explicitObjCName, reqObjCName);
36733673 return ;
36743674 }
0 commit comments