From 764bf831456c5f158651a5a6626b51fa62ebe28f Mon Sep 17 00:00:00 2001 From: Jordan Rose Date: Thu, 6 Oct 2016 09:44:12 -0700 Subject: [PATCH] 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.) --- lib/Sema/CodeSynthesis.cpp | 5 ++++- test/SILGen/objc_attr_NSManaged.swift | 17 +++++++++++++++++ 2 files changed, 21 insertions(+), 1 deletion(-) diff --git a/lib/Sema/CodeSynthesis.cpp b/lib/Sema/CodeSynthesis.cpp index 5ab84b15f57..1d4a7527fda 100644 --- a/lib/Sema/CodeSynthesis.cpp +++ b/lib/Sema/CodeSynthesis.cpp @@ -820,7 +820,10 @@ void TypeChecker::synthesizeAccessorsForStorage(AbstractStorageDecl *storage, // If the decl is stored, convert it to StoredWithTrivialAccessors // by synthesizing the full set of accessors. if (!storage->hasAccessorFunctions()) { - addTrivialAccessorsToStorage(storage, *this); + if (storage->getAttrs().hasAttribute()) + maybeAddAccessorsToVariable(cast(storage), *this); + else + addTrivialAccessorsToStorage(storage, *this); return; } diff --git a/test/SILGen/objc_attr_NSManaged.swift b/test/SILGen/objc_attr_NSManaged.swift index 13193f1daff..25cf49c8753 100644 --- a/test/SILGen/objc_attr_NSManaged.swift +++ b/test/SILGen/objc_attr_NSManaged.swift @@ -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: {{^}$}}