Skip to content

Commit e611e10

Browse files
committed
Mention access note when describing ObjCReason
1 parent 801b268 commit e611e10

File tree

6 files changed

+111
-53
lines changed

6 files changed

+111
-53
lines changed

include/swift/AST/DiagnosticsSema.def

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5878,5 +5878,10 @@ REMARK(attr_objc_name_conflicts_with_access_note, none,
58785878
"source code specifies %3; the access note will be ignored",
58795879
(StringRef, DescriptiveDeclKind, ObjCSelector, ObjCSelector))
58805880

5881+
// Used on invalid @objc diagnostics
5882+
NOTE(note_invalid_attr_added_by_access_note, none,
5883+
"%select{attribute|modifier}0 '%1' was added by access note for %2",
5884+
(bool, StringRef, StringRef))
5885+
58815886
#define UNDEFINE_DIAGNOSTIC_MACROS
58825887
#include "DefineDiagnosticMacros.h"

lib/Sema/TypeCheckAttr.cpp

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -915,6 +915,7 @@ static bool checkObjCDeclContext(Decl *D) {
915915
}
916916

917917
static void diagnoseObjCAttrWithoutFoundation(ObjCAttr *attr, Decl *decl,
918+
ObjCReason reason,
918919
DiagnosticBehavior behavior) {
919920
auto *SF = decl->getDeclContext()->getParentSourceFile();
920921
assert(SF);
@@ -949,6 +950,7 @@ static void diagnoseObjCAttrWithoutFoundation(ObjCAttr *attr, Decl *decl,
949950
ctx.Id_Foundation)
950951
.highlight(attr->getRangeWithAt())
951952
.limitBehavior(behavior);
953+
reason.describe(decl);
952954
}
953955

954956
void AttributeChecker::visitObjCAttr(ObjCAttr *attr) {
@@ -991,6 +993,7 @@ void AttributeChecker::visitObjCAttr(ObjCAttr *attr) {
991993

992994
if (error) {
993995
diagnoseAndRemoveAttr(attr, *error).limitBehavior(behavior);
996+
reason.describe(D);
994997
return;
995998
}
996999

@@ -1078,10 +1081,11 @@ void AttributeChecker::visitObjCAttr(ObjCAttr *attr) {
10781081
// Enum elements require names.
10791082
diagnoseAndRemoveAttr(attr, diag::objc_enum_case_req_name)
10801083
.limitBehavior(behavior);
1084+
reason.describe(D);
10811085
}
10821086

10831087
// Diagnose an @objc attribute used without importing Foundation.
1084-
diagnoseObjCAttrWithoutFoundation(attr, D, behavior);
1088+
diagnoseObjCAttrWithoutFoundation(attr, D, reason, behavior);
10851089
}
10861090

10871091
void AttributeChecker::visitNonObjCAttr(NonObjCAttr *attr) {
@@ -1190,6 +1194,12 @@ void TypeChecker::checkDeclAttributes(Decl *D) {
11901194
else
11911195
Checker.diagnoseAndRemoveAttr(attr, diag::invalid_decl_attribute, attr)
11921196
.limitBehavior(behavior);
1197+
1198+
if (attr->getAddedByAccessNote()) {
1199+
auto notesFileReason = D->getModuleContext()->getAccessNotes().Reason;
1200+
D->diagnose(diag::note_invalid_attr_added_by_access_note,
1201+
attr->isDeclModifier(), attr->getAttrName(), notesFileReason);
1202+
}
11931203
}
11941204
Checker.checkOriginalDefinedInAttrs(D, ODIAttrs);
11951205
}

0 commit comments

Comments
 (0)