Skip to content

Commit 8016b95

Browse files
authored
Merge pull request #40058 from DougGregor/cross-actor-function-value-crash
Fix a crash when diagnosing a missing "await" in a cross-actor call.
2 parents 573ae9b + 9c809db commit 8016b95

File tree

3 files changed

+18
-2
lines changed

3 files changed

+18
-2
lines changed

include/swift/AST/DiagnosticsSema.def

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4490,6 +4490,10 @@ NOTE(actor_isolated_sync_func,none,
44904490
"calls to %0 %1 from outside of its actor context are "
44914491
"implicitly asynchronous",
44924492
(DescriptiveDeclKind, DeclName))
4493+
NOTE(actor_isolated_sync_func_value,none,
4494+
"calls function of type %0 from outside of its actor context are "
4495+
"implicitly asynchronous",
4496+
(Type))
44934497
NOTE(note_distributed_actor_isolated_method,none,
44944498
"distributed actor-isolated %0 %1 declared here",
44954499
(DescriptiveDeclKind, DeclName))

lib/Sema/TypeCheckEffects.cpp

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2862,8 +2862,14 @@ class CheckEffectsCoverage : public EffectsHandlingWalker<CheckEffectsCoverage>
28622862
// Emit a tailored note if the call is implicitly async, meaning the
28632863
// callee is isolated to an actor.
28642864
auto callee = call->getCalledValue();
2865-
Ctx.Diags.diagnose(diag.expr.getStartLoc(), diag::actor_isolated_sync_func,
2866-
callee->getDescriptiveKind(), callee->getName());
2865+
if (callee) {
2866+
Ctx.Diags.diagnose(diag.expr.getStartLoc(), diag::actor_isolated_sync_func,
2867+
callee->getDescriptiveKind(), callee->getName());
2868+
} else {
2869+
Ctx.Diags.diagnose(
2870+
diag.expr.getStartLoc(), diag::actor_isolated_sync_func_value,
2871+
call->getFn()->getType());
2872+
}
28672873
} else {
28682874
Ctx.Diags.diagnose(diag.expr.getStartLoc(),
28692875
diag::async_access_without_await, 0);

test/Concurrency/actor_isolation.swift

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -470,6 +470,12 @@ extension MyActor {
470470
}
471471
}
472472

473+
func testBadImplicitGlobalActorClosureCall() async {
474+
{ @MainActor in }() // expected-error{{expression is 'async' but is not marked with 'await'}}
475+
// expected-note@-1{{calls function of type '@MainActor () -> ()' from outside of its actor context are implicitly asynchronous}}
476+
}
477+
478+
473479
@available(SwiftStdlib 5.1, *)
474480
struct GenericStruct<T> {
475481
@GenericGlobalActor<T> func f() { } // expected-note {{calls to instance method 'f()' from outside of its actor context are implicitly asynchronous}}

0 commit comments

Comments
 (0)