Skip to content

Commit 72bf836

Browse files
committed
[Concurrency] Allow actor classes to inherit from NSObject.
NSObject is guaranteed to have no state and no Swift vtable, and is necessary for Swift classes to implement the NSObject protocol. Allow it (and only it) as the superclass of an actor class, so that actor classes can be exposed to Objective-C.
1 parent 1e040ac commit 72bf836

File tree

2 files changed

+11
-0
lines changed

2 files changed

+11
-0
lines changed

lib/Sema/TypeCheckConcurrency.cpp

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -180,6 +180,14 @@ bool IsActorRequest::evaluate(
180180
if (superclassDecl->isActor())
181181
return true;
182182

183+
// The superclass is 'NSObject', which is known to have no state and no
184+
// superclass.
185+
if (superclassDecl->hasClangNode() &&
186+
superclassDecl->getName().is("NSObject") &&
187+
superclassDecl->getModuleContext()->getName().is("ObjectiveC") &&
188+
actorAttr != nullptr)
189+
return true;
190+
183191
// This class cannot be an actor; complain if the 'actor' modifier was
184192
// provided.
185193
if (actorAttr) {

test/attr/attr_objc_async.swift

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,3 +46,6 @@ actor class MyActor {
4646
// CHECK: @objc @actorIndependent func synchronousGood()
4747
@objc @actorIndependent func synchronousGood() { }
4848
}
49+
50+
// CHECK: @objc actor class MyObjCActor
51+
@objc actor class MyObjCActor: NSObject { }

0 commit comments

Comments
 (0)