Skip to content

Commit bcd6b0f

Browse files
author
Harlan Haskins
committed
[ModuleInterfaces] Don't diagnose @NSManaged properties with accessors
Normally, we diagnose @NSManaged properties that have getters and setters because they are actually supposed to be stored properties with special synthesized accessors. Since we print those accessors in module interfaces, just don't error when we see them. Fixes rdar://56111556
1 parent 2bd55f6 commit bcd6b0f

File tree

2 files changed

+50
-0
lines changed

2 files changed

+50
-0
lines changed

lib/Sema/TypeCheckStorage.cpp

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2538,7 +2538,16 @@ static void finishNSManagedImplInfo(VarDecl *var,
25382538
if (var->isLet())
25392539
diagnoseAndRemoveAttr(var, attr, diag::attr_NSManaged_let_property);
25402540

2541+
SourceFile *parentFile = var->getDeclContext()->getParentSourceFile();
2542+
25412543
auto diagnoseNotStored = [&](unsigned kind) {
2544+
// Skip diagnosing @NSManaged declarations in module interfaces. They are
2545+
// properties that are stored, but have specially synthesized observers
2546+
// and we should allow them to have getters and setters in a module
2547+
// interface.
2548+
if (parentFile && parentFile->Kind == SourceFileKind::Interface)
2549+
return;
2550+
25422551
diagnoseAndRemoveAttr(var, attr, diag::attr_NSManaged_not_stored, kind);
25432552
};
25442553

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
// RUN: %empty-directory(%t)
2+
3+
// This test ensures we can properly load modules that have @NSManaged properties.
4+
5+
// 1. Emit this file to a module interface
6+
// RUN: %target-swift-frontend -typecheck -emit-module-interface-path %t/Module.swiftinterface %s -enable-library-evolution -module-name Module
7+
8+
// 2. Check the interface against what we expect
9+
// RUN: %FileCheck %s < %t/Module.swiftinterface
10+
11+
// 3. Ensure we can load this module from its interface
12+
// RUN: echo 'import Module' | %target-swift-frontend -typecheck - -I %t
13+
14+
// REQUIRES: objc_interop
15+
16+
import CoreData
17+
import Foundation
18+
19+
// CHECK: @objc public class MyObject : CoreData.NSManagedObject {
20+
public class MyObject: NSManagedObject {
21+
// CHECK: @objc @NSManaged dynamic public var myVar: Swift.String {
22+
// CHECK-NEXT: @objc get
23+
// CHECK-NEXT: @objc set
24+
// CHECK-NEXT: }
25+
@NSManaged public var myVar: String
26+
// CHECK: @NSManaged @objc dynamic public var myVar2: Swift.String {
27+
// CHECK-NEXT: @objc get
28+
// CHECK-NEXT: @objc set
29+
// CHECK-NEXT: }
30+
@NSManaged @objc public var myVar2: String
31+
// CHECK: @NSManaged @objc dynamic public var myVar3: Swift.String {
32+
// CHECK-NEXT: @objc get
33+
// CHECK-NEXT: @objc set
34+
// CHECK-NEXT: }
35+
@NSManaged @objc dynamic public var myVar3: String
36+
// CHECK: @NSManaged @objc dynamic public var myVar4: Swift.String {
37+
// CHECK-NEXT: @objc get
38+
// CHECK-NEXT: }
39+
@NSManaged @objc dynamic public private(set) var myVar4: String
40+
// CHECK: }
41+
}

0 commit comments

Comments
 (0)