@@ -1748,7 +1748,7 @@ static ObjCSelector inferObjCName(ValueDecl *decl) {
17481748 diag::objc_override_method_selector_mismatch,
17491749 *attr->getName (), overriddenSelector)
17501750 .limitBehavior (behavior));
1751- fixDeclarationObjCName (diag, decl, attr->getName (),
1751+ fixDeclarationObjCName (diag, decl, attr->getName (). value () ,
17521752 overriddenSelector);
17531753 }
17541754
@@ -1838,8 +1838,9 @@ static ObjCSelector inferObjCName(ValueDecl *decl) {
18381838 auto diag = decl->diagnose (diag::objc_ambiguous_inference_candidate,
18391839 req, proto, *req->getObjCRuntimeName ());
18401840 fixDeclarationObjCName (diag, decl,
1841- decl->getObjCRuntimeName (/* skipIsObjC=*/ true ),
1842- req->getObjCRuntimeName ());
1841+ decl->getObjCRuntimeName (/* skipIsObjC=*/ true )
1842+ .value_or (ObjCSelector ()),
1843+ req->getObjCRuntimeName ().value ());
18431844 };
18441845 diagnoseCandidate (firstReq);
18451846 diagnoseCandidate (req);
@@ -2150,8 +2151,8 @@ bool swift::fixDeclarationName(InFlightDiagnostic &diag, const ValueDecl *decl,
21502151
21512152bool swift::fixDeclarationObjCName (InFlightDiagnostic &diag,
21522153 const Decl *decl,
2153- std::optional< ObjCSelector> nameOpt ,
2154- std::optional< ObjCSelector> targetNameOpt ,
2154+ ObjCSelector name ,
2155+ ObjCSelector targetName ,
21552156 bool ignoreImpliedName) {
21562157 if (decl->isImplicit ())
21572158 return false ;
@@ -2163,9 +2164,6 @@ bool swift::fixDeclarationObjCName(InFlightDiagnostic &diag,
21632164 return false ;
21642165 }
21652166
2166- auto name = *nameOpt;
2167- auto targetName = *targetNameOpt;
2168-
21692167 // Dig out the existing '@objc' attribute on the witness. We don't care
21702168 // about implicit ones because they don't have useful source location
21712169 // information.
@@ -2212,7 +2210,7 @@ bool swift::fixDeclarationObjCName(InFlightDiagnostic &diag,
22122210
22132211 // If the names of the witness and requirement differ, we need to
22142212 // specify the name.
2215- if (name != targetName || ignoreImpliedName) {
2213+ if (targetName && ( name != targetName || ignoreImpliedName) ) {
22162214 out << " (" ;
22172215 out << targetName;
22182216 out << " )" ;
@@ -2907,8 +2905,10 @@ bool swift::diagnoseObjCUnsatisfiedOptReqConflicts(SourceFile &sf) {
29072905 // Fix the '@objc' attribute, if needed.
29082906 if (!bestConflict->canInferObjCFromRequirement (req))
29092907 fixDeclarationObjCName (diag, bestConflict,
2910- bestConflict->getObjCRuntimeName (),
2911- req->getObjCRuntimeName (),
2908+ bestConflict->getObjCRuntimeName ()
2909+ .value_or (ObjCSelector ()),
2910+ req->getObjCRuntimeName ()
2911+ .value_or (ObjCSelector ()),
29122912 /* ignoreImpliedName=*/ true );
29132913 }
29142914
@@ -3277,12 +3277,12 @@ class ObjCImplementationChecker {
32773277 return ObjCSelector ();
32783278 }
32793279
3280- static std::optional< ObjCSelector> getObjCName (ValueDecl *VD) {
3280+ static ObjCSelector getObjCName (ValueDecl *VD) {
32813281 if (!VD->getCDeclName ().empty ()) {
32823282 auto ident = VD->getASTContext ().getIdentifier (VD->getCDeclName ());
32833283 return ObjCSelector (VD->getASTContext (), 0 , { ident });
32843284 }
3285- return VD->getObjCRuntimeName ();
3285+ return VD->getObjCRuntimeName (). value_or ( ObjCSelector ()) ;
32863286 }
32873287
32883288public:
@@ -3427,8 +3427,8 @@ class ObjCImplementationChecker {
34273427 for (auto req : matchedRequirements.matches ) {
34283428 auto diag =
34293429 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));
34323432 if (shouldOfferFix) {
34333433 fixDeclarationObjCName (diag, cand, getObjCName (cand),
34343434 getObjCName (req), /* ignoreImpliedName=*/ true );
@@ -3468,14 +3468,14 @@ class ObjCImplementationChecker {
34683468 auto ext =
34693469 cast<ExtensionDecl>(reqIDC->getImplementationContext ());
34703470 diagnose (ext, diag::objc_implementation_multiple_matching_candidates,
3471- req, * getObjCName (req));
3471+ req, getObjCName (req));
34723472
34733473 for (auto cand : cands.matches ) {
34743474 bool shouldOfferFix = !unmatchedCandidates[cand];
34753475 auto diag =
34763476 diagnose (cand, diag::objc_implementation_candidate_impl_here,
34773477 cand, shouldOfferFix,
3478- getObjCName (req)-> getString (scratch));
3478+ getObjCName (req). getString (scratch));
34793479
34803480 if (shouldOfferFix) {
34813481 fixDeclarationObjCName (diag, cand, getObjCName (cand),
@@ -3650,7 +3650,7 @@ class ObjCImplementationChecker {
36503650
36513651 void diagnoseOutcome (MatchOutcome outcome, ValueDecl *req, ValueDecl *cand,
36523652 ObjCSelector explicitObjCName) {
3653- auto reqObjCName = * getObjCName (req);
3653+ auto reqObjCName = getObjCName (req);
36543654
36553655 switch (outcome) {
36563656 case MatchOutcome::NoRelationship:
@@ -3667,7 +3667,7 @@ class ObjCImplementationChecker {
36673667 case MatchOutcome::WrongImplicitObjCName:
36683668 case MatchOutcome::WrongExplicitObjCName: {
36693669 auto diag = diagnose (cand, diag::objc_implementation_wrong_objc_name,
3670- * getObjCName (cand), cand, reqObjCName);
3670+ getObjCName (cand), cand, reqObjCName);
36713671 fixDeclarationObjCName (diag, cand, explicitObjCName, reqObjCName);
36723672 return ;
36733673 }
0 commit comments