Skip to content

Allow a global-actor-isolated class to inherit from a nonisolated one. #38708

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
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
9 changes: 1 addition & 8 deletions lib/Sema/TypeCheckConcurrency.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3028,14 +3028,7 @@ static bool checkClassGlobalActorIsolation(
switch (superIsolation) {
case ActorIsolation::Unspecified:
case ActorIsolation::Independent:
// Allow ObjC superclasses with unspecified global actors, because we do
// not expect for Objective-C classes to have been universally annotated.
// FIXME: We might choose to tighten this up in Swift 6.
if (superclassDecl->getClangNode())
return false;

// Break out to diagnose the error below.
break;
return false;

case ActorIsolation::ActorInstance:
// This is an error that will be diagnosed later. Ignore it here.
Expand Down
2 changes: 1 addition & 1 deletion test/Concurrency/actor_isolation.swift
Original file line number Diff line number Diff line change
Expand Up @@ -956,7 +956,7 @@ actor Counter {
class C2 { }

@SomeGlobalActor
class C3: C2 { } // expected-error{{global actor 'SomeGlobalActor'-isolated class 'C3' has different actor isolation from nonisolated superclass 'C2'}}
class C3: C2 { } // it's okay to add a global actor to a nonisolated class.

@GenericGlobalActor<U>
class GenericSuper<U> { }
Expand Down
2 changes: 1 addition & 1 deletion test/Concurrency/global_actor_inference.swift
Original file line number Diff line number Diff line change
Expand Up @@ -219,7 +219,7 @@ class SuperclassWithGlobalActors {
func j() { }
}

@GenericGlobalActor<String> // expected-error@+1{{global actor 'GenericGlobalActor<String>'-isolated class 'SubclassWithGlobalActors' has different actor isolation from nonisolated superclass 'SuperclassWithGlobalActors'}}
@GenericGlobalActor<String> // it's okay to add a global actor to nonisolated
class SubclassWithGlobalActors : SuperclassWithGlobalActors {
override func f() { } // okay: inferred to @GenericGlobalActor<Int>

Expand Down