Skip to content

Commit 6862bc3

Browse files
authored
Merge pull request #61481 from tshortli/async-alternative-diag-crash
Sema: Avoid crashing in `diagnoseDeclAsyncAvailability()` when call expr cannot be determined
2 parents 1783e22 + c06b35c commit 6862bc3

File tree

3 files changed

+13
-2
lines changed

3 files changed

+13
-2
lines changed

lib/Sema/TypeCheckAvailability.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3611,8 +3611,8 @@ diagnoseDeclAsyncAvailability(const ValueDecl *D, SourceRange R,
36113611

36123612
if (const AbstractFunctionDecl *afd = dyn_cast<AbstractFunctionDecl>(D)) {
36133613
if (const AbstractFunctionDecl *asyncAlt = afd->getAsyncAlternative()) {
3614-
assert(call && "No call calling async alternative function");
3615-
ctx.Diags.diagnose(call->getLoc(), diag::warn_use_async_alternative);
3614+
SourceLoc diagLoc = call ? call->getLoc() : R.Start;
3615+
ctx.Diags.diagnose(diagLoc, diag::warn_use_async_alternative);
36163616

36173617
if (auto *accessor = dyn_cast<AccessorDecl>(asyncAlt)) {
36183618
SmallString<32> name;

test/attr/Inputs/custom-modules/objc_async.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,9 @@ typedef void (^CompletionHandler)(NSInteger);
1313

1414
-(void)asyncImportSame:(NSInteger)arg completionHandler:(void (^)(NSInteger))handler;
1515
-(void)asyncImportSame:(NSInteger)arg replyTo:(void (^)(NSInteger))handler __attribute__((swift_async(none)));
16+
17+
-(void)simpleOnMainActorWithCompletionHandler:(void (^)(NSInteger))handler __attribute__((swift_attr("@MainActor")));
18+
1619
@end
1720

1821
#pragma clang assume_nonnull end

test/attr/attr_availability_async_rename.swift

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -325,6 +325,14 @@ func asyncContext(t: HandlerTest) async {
325325
t.asyncImportSame(1, replyTo: { _ in })
326326
}
327327

328+
@MainActor
329+
@available(SwiftStdlib 5.5, *)
330+
func mainActorAsyncContext(t: HandlerTest) async {
331+
// expected-warning@+1{{consider using asynchronous alternative function}}
332+
t.simpleOnMainActor(completionHandler: { _ in })
333+
await t.simpleOnMainActor()
334+
}
335+
328336
@available(SwiftStdlib 5.5, *)
329337
func syncContext(t: HandlerTest) {
330338
goodFunc1(value: "Hello") { _ in }

0 commit comments

Comments
 (0)