Skip to content

[Type checker] Don't implicitly propagate @objc to read/modify accessors #21657

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Jan 5, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 16 additions & 1 deletion lib/Sema/TypeCheckDeclObjC.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1066,6 +1066,21 @@ Optional<ObjCReason> shouldMarkAsObjC(const ValueDecl *VD, bool allowImplicit) {
if (VD->getFormalAccess() <= AccessLevel::FilePrivate)
return false;

if (auto accessor = dyn_cast<AccessorDecl>(VD)) {
switch (accessor->getAccessorKind()) {
case AccessorKind::DidSet:
case AccessorKind::Modify:
case AccessorKind::Read:
case AccessorKind::WillSet:
return false;

case AccessorKind::MutableAddress:
case AccessorKind::Address:
case AccessorKind::Get:
case AccessorKind::Set:
break;
}
}
return true;
};

Expand Down Expand Up @@ -1106,7 +1121,7 @@ Optional<ObjCReason> shouldMarkAsObjC(const ValueDecl *VD, bool allowImplicit) {
cast<ExtensionDecl>(VD->getDeclContext())->getAttrs()
.hasAttribute<NonObjCAttr>()))
return None;
if (isMemberOfObjCClassExtension(VD))
if (isMemberOfObjCClassExtension(VD) && canInferImplicitObjC())
return ObjCReason(ObjCReason::MemberOfObjCExtension);
if (isMemberOfObjCMembersClass(VD) && canInferImplicitObjC())
return ObjCReason(ObjCReason::MemberOfObjCMembersClass);
Expand Down
15 changes: 15 additions & 0 deletions test/attr/attr_objc.swift
Original file line number Diff line number Diff line change
Expand Up @@ -2312,3 +2312,18 @@ protocol ObjCProtocolWithWeakProperty {
protocol ObjCProtocolWithUnownedProperty {
unowned var unownedProp: AnyObject { get set } // okay
}

// rdar://problem/46699152: errors about read/modify accessors being implicitly
// marked @objc.
@objc class MyObjCClass: NSObject {}

@objc
extension MyObjCClass {
@objc
static var objCVarInObjCExtension: Bool {
get {
return true
}
set {}
}
}