Skip to content

Commit 6212085

Browse files
committed
[Concurrency] Downgrade isolated call diagnostics when the callee has
an inferred `@preconcurrency` annotation.
1 parent 0c6c369 commit 6212085

File tree

2 files changed

+15
-3
lines changed

2 files changed

+15
-3
lines changed

lib/Sema/TypeCheckConcurrency.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3303,7 +3303,7 @@ namespace {
33033303
} else {
33043304
if (calleeDecl) {
33053305
auto preconcurrency = getContextIsolation().preconcurrency() ||
3306-
calleeDecl->preconcurrency();
3306+
getActorIsolation(calleeDecl).preconcurrency();
33073307
ctx.Diags.diagnose(
33083308
apply->getLoc(), diag::actor_isolated_call_decl,
33093309
*unsatisfiedIsolation,

test/Concurrency/predates_concurrency.swift

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -103,8 +103,8 @@ func testCalls(x: X) {
103103
let _: () -> Void = onMainActorAlways // expected-complete-tns-warning {{converting function value of type '@MainActor () -> ()' to '() -> Void' loses global actor 'MainActor'}}
104104

105105
// both okay with minimal/targeted... an error with complete.
106-
let c = MyModelClass() // expected-complete-tns-error {{call to main actor-isolated initializer 'init()' in a synchronous nonisolated context}}
107-
c.f() // expected-complete-tns-error {{call to main actor-isolated instance method 'f()' in a synchronous nonisolated context}}
106+
let c = MyModelClass() // expected-complete-tns-warning {{call to main actor-isolated initializer 'init()' in a synchronous nonisolated context}}
107+
c.f() // expected-complete-tns-warning {{call to main actor-isolated instance method 'f()' in a synchronous nonisolated context}}
108108
}
109109

110110
func testCallsWithAsync() async {
@@ -207,3 +207,15 @@ class C { // expected-complete-tns-note {{'C' does not conform to the 'Sendable'
207207
}
208208
}
209209

210+
@preconcurrency @MainActor
211+
class MainActorPreconcurrency {}
212+
213+
class InferMainActorPreconcurrency: MainActorPreconcurrency {
214+
static func predatesConcurrency() {}
215+
// expected-note@-1 {{calls to static method 'predatesConcurrency()' from outside of its actor context are implicitly asynchronous}}
216+
}
217+
218+
nonisolated func blah() {
219+
InferMainActorPreconcurrency.predatesConcurrency()
220+
// expected-warning@-1 {{call to main actor-isolated static method 'predatesConcurrency()' in a synchronous nonisolated context}}
221+
}

0 commit comments

Comments
 (0)