@@ -1054,7 +1054,7 @@ Optional<ObjCReason> shouldMarkAsObjC(const ValueDecl *VD, bool allowImplicit) {
1054
1054
protocolContext && protocolContext->isObjC ();
1055
1055
1056
1056
// Local function to determine whether we can implicitly infer @objc.
1057
- auto canInferImplicitObjC = [&] {
1057
+ auto canInferImplicitObjC = [&]( bool allowAnyAccess) {
1058
1058
if (VD->isInvalid ())
1059
1059
return false ;
1060
1060
if (VD->isOperator ())
@@ -1064,7 +1064,7 @@ Optional<ObjCReason> shouldMarkAsObjC(const ValueDecl *VD, bool allowImplicit) {
1064
1064
if (!allowImplicit && VD->isImplicit ())
1065
1065
return false ;
1066
1066
1067
- if (VD->getFormalAccess () <= AccessLevel::FilePrivate)
1067
+ if (!allowAnyAccess && VD->getFormalAccess () <= AccessLevel::FilePrivate)
1068
1068
return false ;
1069
1069
1070
1070
if (auto accessor = dyn_cast<AccessorDecl>(VD)) {
@@ -1115,17 +1115,22 @@ Optional<ObjCReason> shouldMarkAsObjC(const ValueDecl *VD, bool allowImplicit) {
1115
1115
// A member of an @objc protocol is implicitly @objc.
1116
1116
if (isMemberOfObjCProtocol)
1117
1117
return ObjCReason (ObjCReason::MemberOfObjCProtocol);
1118
+
1118
1119
// A @nonobjc is not @objc, even if it is an override of an @objc, so check
1119
1120
// for @nonobjc first.
1120
1121
if (VD->getAttrs ().hasAttribute <NonObjCAttr>() ||
1121
1122
(isa<ExtensionDecl>(VD->getDeclContext ()) &&
1122
1123
cast<ExtensionDecl>(VD->getDeclContext ())->getAttrs ()
1123
1124
.hasAttribute <NonObjCAttr>()))
1124
1125
return None;
1125
- if (isMemberOfObjCClassExtension (VD) && canInferImplicitObjC ())
1126
+
1127
+ if (isMemberOfObjCClassExtension (VD) &&
1128
+ canInferImplicitObjC (/* allowAnyAccess*/ true ))
1126
1129
return ObjCReason (ObjCReason::MemberOfObjCExtension);
1127
- if (isMemberOfObjCMembersClass (VD) && canInferImplicitObjC ())
1130
+ if (isMemberOfObjCMembersClass (VD) &&
1131
+ canInferImplicitObjC (/* allowAnyAccess*/ false ))
1128
1132
return ObjCReason (ObjCReason::MemberOfObjCMembersClass);
1133
+
1129
1134
// An override of an @objc declaration is implicitly @objc.
1130
1135
if (VD->getOverriddenDecl () && VD->getOverriddenDecl ()->isObjC ())
1131
1136
return ObjCReason (ObjCReason::OverridesObjC);
@@ -1177,7 +1182,7 @@ Optional<ObjCReason> shouldMarkAsObjC(const ValueDecl *VD, bool allowImplicit) {
1177
1182
// (and extensions thereof) whose class hierarchies originate in Objective-C,
1178
1183
// e.g., which derive from NSObject, so long as the members have internal
1179
1184
// access or greater.
1180
- if (!canInferImplicitObjC ())
1185
+ if (!canInferImplicitObjC (/* allowAnyAccess */ false ))
1181
1186
return None;
1182
1187
1183
1188
// If this declaration is part of a class with implicitly @objc members,
0 commit comments