Skip to content

[Actor isolation] Fix a crash involving global actors, ObjC, and conformances #35714

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 6 additions & 2 deletions lib/Sema/TypeCheckProtocol.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2749,8 +2749,12 @@ bool ConformanceChecker::checkActorIsolation(
//
// However, we allow this case when the requirement was imported, because
// it might not have been annotated.
if (witnessGlobalActor && !requirementGlobalActor &&
!requirement->hasClangNode()) {
if (witnessGlobalActor && !requirementGlobalActor) {
// If the requirement was imported from Objective-C, it may not have been
// annotated appropriately. Allow the mismatch.
if (requirement->hasClangNode())
return false;

witness->diagnose(
diag::global_actor_isolated_witness, witness->getDescriptiveKind(),
witness->getName(), witnessGlobalActor, Proto->getName());
Expand Down
11 changes: 10 additions & 1 deletion test/ClangImporter/objc_async_conformance.swift
Original file line number Diff line number Diff line change
Expand Up @@ -64,4 +64,13 @@ class SelectorOK2 : NSObject, RequiredObserverOnlyCompletion {
class Rock : NSObject, Rollable {
func roll(completionHandler: @escaping () -> Void) { completionHandler() }
func roll() { roll(completionHandler: {}) }
}
}

// Crash involving actor isolation checking.
class C5 {
@MainActor @objc var allOperations: [String] = []
}

class C6: C5, ServiceProvider {
@MainActor func allOperations() async -> [String] { [] }
}