@@ -428,35 +428,52 @@ static bool checkObjCInForeignClassContext(const ValueDecl *VD,
428
428
return true ;
429
429
}
430
430
431
+ // / Whether the given declaration can be exposed as Objective-C.
432
+ static bool canExposeActorIsolatedAsObjC (
433
+ const ValueDecl *value, const ActorIsolation &isolation) {
434
+ if (isAccessibleAcrossActors (
435
+ const_cast <ValueDecl *>(value), isolation, value->getDeclContext ()))
436
+ return true ;
437
+
438
+ // An async function can be exposed as Objective-C.
439
+ if (auto func = dyn_cast<AbstractFunctionDecl>( value))
440
+ return func->hasAsync ();
441
+
442
+ return false ;
443
+ }
444
+
431
445
// / Actor-isolated declarations cannot be @objc.
432
- static bool checkObjCActorIsolation (const ValueDecl *VD,
433
- ObjCReason Reason) {
446
+ static bool checkObjCActorIsolation (const ValueDecl *VD, ObjCReason Reason) {
434
447
// Check actor isolation.
435
- switch (auto restriction = ActorIsolationRestriction::forDeclaration (
436
- const_cast <ValueDecl *>(VD), VD->getDeclContext (),
437
- /* fromExpression=*/ false )) {
438
- case ActorIsolationRestriction::CrossActorSelf:
448
+ switch (auto isolation = getActorIsolation (const_cast <ValueDecl *>(VD))) {
449
+ case ActorIsolation::ActorInstance:
450
+ if (!canExposeActorIsolatedAsObjC (VD, isolation)) {
451
+ // Actor-isolated functions cannot be @objc.
452
+ VD->diagnose (diag::actor_isolated_objc, VD->getDescriptiveKind (),
453
+ VD->getName ());
454
+ Reason.describe (VD);
455
+ if (auto FD = dyn_cast<FuncDecl>(VD)) {
456
+ addAsyncNotes (const_cast <FuncDecl *>(FD));
457
+ }
458
+
459
+ return true ;
460
+ }
461
+
439
462
// FIXME: Substitution map?
440
463
diagnoseNonSendableTypesInReference (
441
464
const_cast <ValueDecl *>(VD), VD->getDeclContext (),
442
465
VD->getLoc (), SendableCheckReason::ObjC);
443
466
return false ;
444
- case ActorIsolationRestriction::ActorSelf:
445
- // Actor-isolated functions cannot be @objc.
446
- VD->diagnose (diag::actor_isolated_objc, VD->getDescriptiveKind (),
447
- VD->getName ());
448
- Reason.describe (VD);
449
- if (auto FD = dyn_cast<FuncDecl>(VD)) {
450
- addAsyncNotes (const_cast <FuncDecl *>(FD));
451
- }
452
- return true ;
453
467
454
- case ActorIsolationRestriction::GlobalActorUnsafe :
455
- case ActorIsolationRestriction::GlobalActor :
468
+ case ActorIsolation::GlobalActor :
469
+ case ActorIsolation::GlobalActorUnsafe :
456
470
// FIXME: Consider whether to limit @objc on global-actor-qualified
457
- // declarations.
458
- case ActorIsolationRestriction::Unrestricted:
459
- case ActorIsolationRestriction::Unsafe:
471
+ // declarations. Perhaps only allow main actor, which we can reflect
472
+ // in the generated header.
473
+ return false ;
474
+
475
+ case ActorIsolation::Independent:
476
+ case ActorIsolation::Unspecified:
460
477
return false ;
461
478
}
462
479
}
0 commit comments