Skip to content

Commit edd3f35

Browse files
committed
Apply behavior limit to selector override errors
1 parent 918e5c8 commit edd3f35

File tree

1 file changed

+16
-6
lines changed

1 file changed

+16
-6
lines changed

lib/Sema/TypeCheckDeclObjC.cpp

Lines changed: 16 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1602,8 +1602,9 @@ static ObjCSelector inferObjCName(ValueDecl *decl) {
16021602

16031603
auto attr = decl->getAttrs().getAttribute<ObjCAttr>();
16041604

1605-
/// Set the @objc name.
16061605
ASTContext &ctx = decl->getASTContext();
1606+
1607+
/// Set the @objc name.
16071608
auto setObjCName = [&](ObjCSelector selector) {
16081609
// If there already is an @objc attribute, update its name.
16091610
if (attr) {
@@ -1627,13 +1628,18 @@ static ObjCSelector inferObjCName(ValueDecl *decl) {
16271628
// Determine whether there is a name conflict.
16281629
bool shouldFixName = !attr || !attr->hasName();
16291630
if (attr && attr->hasName() && *attr->getName() != overriddenSelector) {
1631+
auto reason = objCReasonForObjCAttr(attr);
1632+
auto behavior = behaviorLimitForObjCReason(reason, ctx);
1633+
16301634
// If the user explicitly wrote the incorrect name, complain.
16311635
if (!attr->isNameImplicit()) {
16321636
{
1633-
auto diag = ctx.Diags.diagnose(
1634-
attr->AtLoc,
1635-
diag::objc_override_method_selector_mismatch,
1636-
*attr->getName(), overriddenSelector);
1637+
auto diag = std::move(
1638+
ctx.Diags.diagnose(
1639+
attr->AtLoc,
1640+
diag::objc_override_method_selector_mismatch,
1641+
*attr->getName(), overriddenSelector)
1642+
.limitBehavior(behavior));
16371643
fixDeclarationObjCName(diag, decl, attr->getName(),
16381644
overriddenSelector);
16391645
}
@@ -1661,6 +1667,9 @@ static ObjCSelector inferObjCName(ValueDecl *decl) {
16611667
bool shouldFixName = !attr || !attr->hasName();
16621668
if (attr && attr->hasName() &&
16631669
*attr->getName() != overriddenNameAsSel) {
1670+
auto reason = objCReasonForObjCAttr(attr);
1671+
auto behavior = behaviorLimitForObjCReason(reason, ctx);
1672+
16641673
// If the user explicitly wrote the wrong name, complain.
16651674
if (!attr->isNameImplicit()) {
16661675
SourceLoc diagLoc = attr->AtLoc, firstNameLoc;
@@ -1674,7 +1683,8 @@ static ObjCSelector inferObjCName(ValueDecl *decl) {
16741683
overriddenName)
16751684
.fixItReplaceChars(firstNameLoc,
16761685
attr->getRParenLoc(),
1677-
overriddenName.str());
1686+
overriddenName.str())
1687+
.limitBehavior(behavior);
16781688
overridden->diagnose(diag::overridden_here);
16791689
}
16801690

0 commit comments

Comments
 (0)