SR-2673: @NSManaged property can't satisfy protocol requirement (#5141)

Targeted fix for SR-2673: if a potential protocol witness is
@NSManaged, add accessors the NSManaged way, not the stored property
way.

There's probably more weirdness around here, so I'll clone the bug to
go through maybeAddAccessorsToVariable a lot more often. (Lazy
properties could easily be broken in the same way.)
This commit is contained in:
Jordan Rose
2016-10-06 09:44:12 -07:00
committed by GitHub
parent ac3a215d9a
commit 764bf83145
2 changed files with 21 additions and 1 deletions

View File

@@ -820,6 +820,9 @@ void TypeChecker::synthesizeAccessorsForStorage(AbstractStorageDecl *storage,
// If the decl is stored, convert it to StoredWithTrivialAccessors
// by synthesizing the full set of accessors.
if (!storage->hasAccessorFunctions()) {
if (storage->getAttrs().hasAttribute<NSManagedAttr>())
maybeAddAccessorsToVariable(cast<VarDecl>(storage), *this);
else
addTrivialAccessorsToStorage(storage, *this);
return;
}

View File

@@ -78,6 +78,19 @@ func testFinal(_ obj: FinalGizmo) -> String {
return obj.y
}
// SR-2673: @NSManaged property can't satisfy protocol requirement
@objc protocol ObjCProto {
var managedProp: String { get set }
var managedExtProp: AnyObject { get }
}
class ProtoAdopter: Gizmo, ObjCProto {
@NSManaged var managedProp: String
}
extension ProtoAdopter {
@NSManaged var managedExtProp: AnyObject
}
// CHECK-NOT: sil hidden @_TToFC19objc_attr_NSManaged10SwiftGizmog1xCS_1X : $@convention(objc_method) (SwiftGizmo) -> @autoreleased X
// CHECK-NOT: sil hidden @_TToFC19objc_attr_NSManaged10SwiftGizmos1xCS_1X
@@ -100,3 +113,7 @@ func testFinal(_ obj: FinalGizmo) -> String {
// CHECK-NEXT: #SwiftGizmo.init!initializer.1: _TFC19objc_attr_NSManaged10FinalGizmoc
// CHECK-NEXT: #FinalGizmo.deinit!deallocator: _TFC19objc_attr_NSManaged10FinalGizmoD
// CHECK-NEXT: }
// CHECK-LABEL: sil_vtable ProtoAdopter {
// CHECK-NOT: managed{{.*}}Prop
// CHECK: {{^}$}}