Skip to content

Commit c4e40ac

Browse files
author
Nathan Hawes
committed
[ModuleInterface] Allow non-mutable IBOutlet instance properties in module interfaces
If an IBOutlet property is public private(set), it's interface only has a getter. Consuming this interface was triggering a diagnostic that IBOutlet properties must be mutable. This patch bypasses this check for module interfaces. Resolves rdar://problem/49856177
1 parent f42c703 commit c4e40ac

File tree

2 files changed

+25
-2
lines changed

2 files changed

+25
-2
lines changed

lib/Sema/TypeCheckAttr.cpp

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -415,8 +415,13 @@ void AttributeEarlyChecker::visitIBOutletAttr(IBOutletAttr *attr) {
415415
if (!VD->getDeclContext()->getSelfClassDecl() || VD->isStatic())
416416
diagnoseAndRemoveAttr(attr, diag::invalid_iboutlet);
417417

418-
if (!VD->isSettable(nullptr))
419-
diagnoseAndRemoveAttr(attr, diag::iboutlet_only_mutable);
418+
if (!VD->isSettable(nullptr)) {
419+
// Allow non-mutable IBOutlet properties in module interfaces,
420+
// as they may have been private(set)
421+
SourceFile *Parent = VD->getDeclContext()->getParentSourceFile();
422+
if (!Parent || Parent->Kind != SourceFileKind::Interface)
423+
diagnoseAndRemoveAttr(attr, diag::iboutlet_only_mutable);
424+
}
420425

421426
// Verify that the field type is valid as an outlet.
422427
auto type = VD->getType();
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
// REQUIRES: objc_interop
2+
3+
// RUN: %empty-directory(%t)
4+
// RUN: %target-swift-frontend -typecheck -enable-library-evolution -disable-objc-attr-requires-foundation-module -emit-parseable-module-interface-path %t/Foo.swiftinterface %s
5+
// RUN: %FileCheck %s -input-file %t/Foo.swiftinterface
6+
// RUN: %target-swift-frontend -build-module-from-parseable-interface %t/Foo.swiftinterface -o %t/Foo.swiftmodule
7+
8+
// Test the interface we generate for @IBOutlet private(set) properties is
9+
// consumable.
10+
11+
@objc public class MyType {}
12+
13+
open class Bar {
14+
// CHECK: @objc @IBOutlet weak public var foo: MyType! {
15+
// CHECK-NEXT: get
16+
// CHECK-NEXT: }
17+
@IBOutlet public private(set) weak var foo: MyType!
18+
}

0 commit comments

Comments
 (0)