Skip to content

Commit dbc021a

Browse files
committed
[Concurrency] Don't let "unsafe" inference block other inference.
The presence of an unsafe global-actor attribute on something we can infer from (e.g., a witnessed protocol requirement or overridden declaration) was preventing propagation of actor-isolation attributes from outer scopes. Only take "positive" results from such places.
1 parent d97c867 commit dbc021a

File tree

2 files changed

+11
-2
lines changed

2 files changed

+11
-2
lines changed

lib/Sema/TypeCheckConcurrency.cpp

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2669,7 +2669,8 @@ ActorIsolation ActorIsolationRequest::evaluate(
26692669
// If the declaration witnesses a protocol requirement that is isolated,
26702670
// use that.
26712671
if (auto witnessedIsolation = getIsolationFromWitnessedRequirements(value)) {
2672-
return inferredIsolation(*witnessedIsolation);
2672+
if (auto inferred = inferredIsolation(*witnessedIsolation))
2673+
return inferred;
26732674
}
26742675

26752676
// If the declaration is a class with a superclass that has specified
@@ -2688,7 +2689,8 @@ ActorIsolation ActorIsolationRequest::evaluate(
26882689
superclassIsolation = superclassIsolation.subst(subs);
26892690
}
26902691

2691-
return inferredIsolation(superclassIsolation);
2692+
if (auto inferred = inferredIsolation(superclassIsolation))
2693+
return inferred;
26922694
}
26932695
}
26942696
}

test/Concurrency/global_actor_inference.swift

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -361,6 +361,13 @@ struct StructUGA2: UGA {
361361
nonisolated func req() { }
362362
}
363363

364+
@SomeGlobalActor
365+
struct StructUGA3: UGA {
366+
func req() {
367+
sibling()
368+
}
369+
}
370+
364371
@GenericGlobalActor<String>
365372
func testUGA<T: UGA>(_ value: T) {
366373
value.req() // expected-error{{instance method 'req()' isolated to global actor 'SomeGlobalActor' can not be referenced from different global actor 'GenericGlobalActor<String>'}}

0 commit comments

Comments
 (0)