Skip to content

Commit 9ca2fbd

Browse files
committed
Clarify behavior of access note with ObjCName only
An access note with an ObjCName property but no ObjC property now implicitly sets ObjC to true. ObjC: false with an ObjCName is still illegal.
1 parent bde58ed commit 9ca2fbd

File tree

3 files changed

+9
-7
lines changed

3 files changed

+9
-7
lines changed

lib/AST/AccessNotes.cpp

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -255,8 +255,12 @@ void MappingTraits<AccessNote>::mapping(IO &io, AccessNote &note) {
255255
}
256256

257257
StringRef MappingTraits<AccessNote>::validate(IO &io, AccessNote &note) {
258-
if (!note.ObjC.getValueOr(true) && note.ObjCName.hasValue())
258+
if (note.ObjCName.hasValue()) {
259+
if (!note.ObjC)
260+
note.ObjC = true;
261+
else if (!*note.ObjC)
259262
return "cannot have an 'ObjCName' if 'ObjC' is false";
263+
}
260264

261265
return "";
262266
}

lib/Sema/TypeCheckDeclPrimary.cpp

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1500,7 +1500,7 @@ static void applyAccessNote(ValueDecl *VD, const AccessNote &note,
15001500
ASTContext &ctx = VD->getASTContext();
15011501

15021502
addOrRemoveAttr<ObjCAttr>(VD, notes, note.ObjC, [&]() {
1503-
return ObjCAttr::create(ctx, note.ObjCName, true);
1503+
return ObjCAttr::create(ctx, note.ObjCName, false);
15041504
});
15051505

15061506
addOrRemoveAttr<DynamicAttr>(VD, notes, note.Dynamic, [&]{
@@ -1509,11 +1509,9 @@ static void applyAccessNote(ValueDecl *VD, const AccessNote &note,
15091509

15101510
if (note.ObjCName) {
15111511
auto attr = VD->getAttrs().getAttribute<ObjCAttr>();
1512+
assert(attr && "ObjCName set, but ObjCAttr not true or did not apply???");
15121513

1513-
if (!attr) {
1514-
// TODO: diagnose use of ObjCName without ObjC: true
1515-
}
1516-
else if (!attr->hasName()) {
1514+
if (!attr->hasName()) {
15171515
attr->setName(*note.ObjCName, true);
15181516
ctx.Diags.diagnose(attr->getLocation(),
15191517
diag::attr_objc_name_changed_by_access_note,

test/SILGen/objc_access_notes.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -107,7 +107,7 @@ class Hoozit : Gizmo {
107107

108108
// NS_RETURNS_RETAINED by family (-copy)
109109
// expected-warning@+2 {{access note for fancy test suite adds attribute 'objc' to this instance method}}
110-
// expected-note@+1 {{add attribute explicitly to silence this warning}} {{3-3=@objc }}
110+
// expected-note@+1 {{add attribute explicitly to silence this warning}} {{3-3=@objc(copyDuplicate) }}
111111
func makeDuplicate() -> Gizmo { return self }
112112
// CHECK-LABEL: sil hidden [thunk] [ossa] @$s11objc_thunks6HoozitC13makeDuplicateSo5GizmoCyFTo : $@convention(objc_method) (Hoozit) -> @owned Gizmo
113113
// CHECK: bb0([[THIS:%.*]] : @unowned $Hoozit):

0 commit comments

Comments
 (0)