Skip to content

Commit 8643de9

Browse files
committed
[PrintAsObjC] Respect private(set) on class properties.
rdar://problem/24564858
1 parent 7ac4dda commit 8643de9

File tree

2 files changed

+26
-3
lines changed

2 files changed

+26
-3
lines changed

lib/PrintAsObjC/PrintAsObjC.cpp

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -655,7 +655,7 @@ class ObjCPrinter : private DeclVisitor<ObjCPrinter>,
655655
VD->getObjCGetterSelector() != ObjCSelector(ctx, 0, { objCName })) {
656656
os << ", getter=" << VD->getObjCGetterSelector().getString(buffer);
657657
}
658-
if (VD->isSettable(nullptr)) {
658+
if (isSettable) {
659659
if (hasReservedName ||
660660
VD->getObjCSetterSelector() !=
661661
VarDecl::getDefaultObjCSetterSelector(ctx, objCName)) {
@@ -689,8 +689,10 @@ class ObjCPrinter : private DeclVisitor<ObjCPrinter>,
689689
// Older Clangs don't support class properties, so print the accessors as
690690
// well. This is harmless.
691691
printAbstractFunctionAsMethod(VD->getGetter(), true);
692-
if (auto setter = VD->getSetter())
693-
printAbstractFunctionAsMethod(setter, true);
692+
if (isSettable) {
693+
assert(VD->getSetter() && "settable ObjC property missing setter decl");
694+
printAbstractFunctionAsMethod(VD->getSetter(), true);
695+
}
694696
} else {
695697
os << "\n";
696698
}

test/PrintAsObjC/classes.swift

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -414,6 +414,14 @@ public class NonObjCClass { }
414414
// CHECK-NEXT: @property (nonatomic, getter=isAnimated) BOOL animated;
415415
// CHECK-NEXT: @property (nonatomic, getter=register, setter=setRegister:) BOOL register_;
416416
// CHECK-NEXT: @property (nonatomic, readonly, strong, getter=this) Properties * _Nonnull this_;
417+
// CHECK-NEXT: @property (nonatomic, readonly) NSInteger privateSetter;
418+
// CHECK-NEXT: @property (nonatomic, readonly, getter=customGetterNameForPrivateSetter) BOOL privateSetterCustomNames;
419+
// CHECK-NEXT: SWIFT_CLASS_PROPERTY(@property (nonatomic, class, readonly) NSInteger privateSetter;)
420+
// CHECK-NEXT: + (NSInteger)privateSetter;
421+
// CHECK-NEXT: SWIFT_CLASS_PROPERTY(@property (nonatomic, class, readonly, getter=customGetterNameForPrivateSetter) BOOL privateSetterCustomNames;)
422+
// CHECK-NEXT: + (BOOL)customGetterNameForPrivateSetter;
423+
// CHECK-NEXT: SWIFT_CLASS_PROPERTY(@property (nonatomic, class, readonly) NSInteger sharedConstant;)
424+
// CHECK-NEXT: + (NSInteger)sharedConstant;
417425
// CHECK-NEXT: init
418426
// CHECK-NEXT: @end
419427
@objc class Properties {
@@ -494,6 +502,19 @@ public class NonObjCClass { }
494502

495503
var register: Bool = false
496504
var this: Properties { return self }
505+
506+
private(set) var privateSetter = 2
507+
private(set) var privateSetterCustomNames: Bool {
508+
@objc(customGetterNameForPrivateSetter) get { return true }
509+
@objc(customSetterNameForPrivateSetter:) set {}
510+
}
511+
512+
static private(set) var privateSetter = 2
513+
class private(set) var privateSetterCustomNames: Bool {
514+
@objc(customGetterNameForPrivateSetter) get { return true }
515+
@objc(customSetterNameForPrivateSetter:) set {}
516+
}
517+
static let sharedConstant = 2
497518
}
498519

499520
// CHECK-LABEL: @interface PropertiesOverridden

0 commit comments

Comments
 (0)