Skip to content

Commit 2ff70e0

Browse files
committed
Replace existing access control in objcImpl fixit
The fix-it suggesting that an unmatched `@objc`-able member can be turned `private` always suggested adding a new modifier, even if one already existed. Make it suggest replacing the existing one instead.
1 parent bf64711 commit 2ff70e0

File tree

2 files changed

+11
-5
lines changed

2 files changed

+11
-5
lines changed

lib/Sema/TypeCheckDeclObjC.cpp

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3542,10 +3542,16 @@ class ObjCImplementationChecker {
35423542
diagnose(cand, diag::member_of_objc_implementation_not_objc_or_final,
35433543
cand, cand->getDeclContext()->getSelfClassDecl());
35443544

3545-
if (canBeRepresentedInObjC(cand))
3546-
diagnose(cand, diag::fixit_add_private_for_objc_implementation,
3547-
cand->getDescriptiveKind())
3548-
.fixItInsert(cand->getAttributeInsertionLoc(true), "private ");
3545+
if (canBeRepresentedInObjC(cand)) {
3546+
auto diagnostic =
3547+
diagnose(cand, diag::fixit_add_private_for_objc_implementation,
3548+
cand->getDescriptiveKind());
3549+
if (auto modifier = cand->getAttrs().getAttribute<AccessControlAttr>())
3550+
diagnostic.fixItReplace(modifier->getRange(), "private");
3551+
else
3552+
diagnostic.fixItInsert(cand->getAttributeInsertionLoc(true),
3553+
"private ");
3554+
}
35493555

35503556
diagnose(cand, diag::fixit_add_final_for_objc_implementation,
35513557
cand->getDescriptiveKind())

test/decl/ext/objc_implementation.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -114,7 +114,7 @@ protocol EmptySwiftProto {}
114114

115115
internal var propertyNotFromHeader1: CInt
116116
// expected-warning@-1 {{property 'propertyNotFromHeader1' does not match any property declared in the headers for 'ObjCClass'; did you use the property's Swift name?; this will become an error before '@_objcImplementation' is stabilized}}
117-
// expected-note@-2 {{add 'private' or 'fileprivate' to define an Objective-C-compatible property not declared in the header}} {{3-3=private }}
117+
// expected-note@-2 {{add 'private' or 'fileprivate' to define an Objective-C-compatible property not declared in the header}} {{3-11=private}}
118118
// expected-note@-3 {{add 'final' to define a Swift property that cannot be overridden}} {{3-3=final }}
119119

120120
@objc private var propertyNotFromHeader2: CInt

0 commit comments

Comments
 (0)