Skip to content

Commit 29a2d32

Browse files
committed
Avoid objcImpl @_hasStorage in module interfaces
If an `@objc implementation extension` had a public stored property with an observer, Swift would print `@_hasStorage` on the extension. This is Not Good because in a module interface, an objcImpl extension appears to be an ordinary extension, and properties in ordinary extensions are not supposed to have storage. Suppress printing this attribute in objcImpl extensions to avoid this problem. Partially fixes rdar://144811653 by suppressing emission of bad attributes.
1 parent c44284d commit 29a2d32

File tree

2 files changed

+10
-2
lines changed

2 files changed

+10
-2
lines changed

lib/AST/ASTPrinter.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1332,8 +1332,8 @@ void PrintAST::printAttributes(const Decl *D) {
13321332

13331333
if (!Options.PrintForSIL) {
13341334
// Don't print @_hasStorage if the value is simply stored, or the
1335-
// decl is resilient.
1336-
if (vd->isResilient() ||
1335+
// decl is resilient or in an `@objc @implementation` extension.
1336+
if (vd->isResilient() || isInObjCImpl(vd) ||
13371337
(vd->getImplInfo().isSimpleStored() &&
13381338
!hasLessAccessibleSetter(vd)))
13391339
Options.ExcludeAttrList.push_back(DeclAttrKind::HasStorage);

test/ModuleInterface/objc_implementation.swift

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,9 @@ import Foundation
2121
// @objc should be omitted on extensions
2222
// NEGATIVE-NOT: @objc{{.*}} extension
2323

24+
// Stored properties in objcImpl extensions shouldn't have @_hasStorage
25+
// NEGATIVE-NOT: @_hasStorage
26+
2427
//
2528
// @_objcImplementation class
2629
//
@@ -42,6 +45,11 @@ import Foundation
4245
// CHECK-DAG: final public var implProperty2: ObjectiveC.NSObject? { get set }
4346
public final var implProperty2: NSObject?
4447

48+
// CHECK-DAG: final public var implProperty3: ObjectiveC.NSObject? {
49+
public final var implProperty3: NSObject? {
50+
didSet { }
51+
}
52+
4553
// CHECK-NOT: func mainMethod
4654
@objc public func mainMethod(_: Int32) { print(implProperty) }
4755

0 commit comments

Comments
 (0)