Skip to content

Commit b829e86

Browse files
committed
[Move-only-types] Break cycle with OpaqueReadOwnershipRequest and @objc selector
The interface-type computation in OpaqueReadOwnershipRequest is causing a cycle with `@objc` names for the getter/setter of a property. Break the cycle by relying on the fact that `@objc` names can only be directly on the getter/setter, not on some other accessor, so we can go through `getAccessor` for both cases. I am not convinced that we won't have additional issues related to the interface-type computation in OpaqueReadOwnershipRequest, but I couldn't see any obvious ones in the code base either. Fixes rdar://106575164.
1 parent b412c6c commit b829e86

File tree

3 files changed

+39
-2
lines changed

3 files changed

+39
-2
lines changed

lib/AST/Decl.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6309,7 +6309,7 @@ getNameFromObjcAttribute(const ObjCAttr *attr, DeclName preferredName) {
63096309
ObjCSelector
63106310
AbstractStorageDecl::getObjCGetterSelector(Identifier preferredName) const {
63116311
// If the getter has an @objc attribute with a name, use that.
6312-
if (auto getter = getOpaqueAccessor(AccessorKind::Get)) {
6312+
if (auto getter = getAccessor(AccessorKind::Get)) {
63136313
if (auto name = getNameFromObjcAttribute(getter->getAttrs().
63146314
getAttribute<ObjCAttr>(), preferredName))
63156315
return *name;
@@ -6339,7 +6339,7 @@ AbstractStorageDecl::getObjCGetterSelector(Identifier preferredName) const {
63396339
ObjCSelector
63406340
AbstractStorageDecl::getObjCSetterSelector(Identifier preferredName) const {
63416341
// If the setter has an @objc attribute with a name, use that.
6342-
auto setter = getOpaqueAccessor(AccessorKind::Set);
6342+
auto setter = getAccessor(AccessorKind::Set);
63436343
auto objcAttr = setter ? setter->getAttrs().getAttribute<ObjCAttr>()
63446344
: nullptr;
63456345
if (auto name = getNameFromObjcAttribute(objcAttr, DeclName(preferredName))) {
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
#import <Foundation/NSObject.h>
2+
#import <Foundation/NSUUID.h>
3+
4+
__attribute__((objc_subclassing_restricted))
5+
__attribute__((swift_name("TricksyClass")))
6+
__attribute__((external_source_symbol(language="Swift", defined_in="MyModule", generated_declaration)))
7+
@interface CPTricksyClass : NSObject
8+
9+
@end
10+
11+
@protocol P
12+
@property(readonly) NSUUID *uuid;
13+
@end
14+
15+
@interface CPTricksyClass() <P>
16+
@end
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
// RUN: %target-typecheck-verify-swift -target %target-cpu-apple-macosx10.15 -swift-version 5 -import-objc-header %S/Inputs/move_only_types_cycle.h
2+
// REQUIRES: objc_interop
3+
// REQUIRES: OS=macosx
4+
5+
// This test triggered a cyclic dependency between @objc getter selector
6+
// checking and some checking for move-only types, which is both horrifying and
7+
// exciting at the same time.
8+
9+
import Foundation
10+
11+
@objc(CPTricksyClass)
12+
public class TricksyClass: NSObject {
13+
public enum Color {
14+
case red
15+
}
16+
17+
var id = UUID()
18+
}
19+
20+
extension TricksyClass.Color {
21+
}

0 commit comments

Comments
 (0)