Skip to content

Commit c6b6bcd

Browse files
committed
Add fix recommendation
This adds a note with a possible way to fix the issue, recommending removing the `async` effect and wrapping the body of the function in a task.
1 parent fad7453 commit c6b6bcd

File tree

3 files changed

+9
-1
lines changed

3 files changed

+9
-1
lines changed

include/swift/AST/DiagnosticsSema.def

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1451,6 +1451,8 @@ NOTE(fixit_rename_in_swift,none,
14511451
"change Swift name to %0", (DeclName))
14521452
NOTE(fixit_rename_in_objc,none,
14531453
"change Objective-C selector to %0", (ObjCSelector))
1454+
NOTE(remove_async_add_task,none,
1455+
"remove 'async' and wrap in 'Task' to use concurrency in %0", (DeclName))
14541456
ERROR(no_objc_tagged_pointer_not_class_protocol,none,
14551457
"@unsafe_no_objc_tagged_pointer can only be applied to class protocols",
14561458
())

lib/Sema/TypeCheckAttr.cpp

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -504,6 +504,9 @@ validateIBActionSignature(ASTContext &ctx, DeclAttribute *attr,
504504
if (FD->isAsyncContext()) {
505505
ctx.Diags.diagnose(FD->getAsyncLoc(), diag::attr_decl_async,
506506
attr->getAttrName(), FD->getDescriptiveKind());
507+
508+
ctx.Diags.diagnose(FD->getAsyncLoc(), diag::remove_async_add_task,
509+
FD->getName());
507510
valid = false;
508511
}
509512

test/attr/attr_ibaction.swift

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,8 +43,11 @@ class IBActionWrapperTy {
4343
func evenMoreMagic(_: AnyObject) -> () {} // no-warning
4444

4545
@available(macOS 10.15, *)
46-
@IBAction // expected-error@+1 {{@IBAction instance method cannot be async}}
46+
@IBAction
4747
func asyncIBAction(_: AnyObject) async -> () {}
48+
// expected-error@-1 {{@IBAction instance method cannot be async}}
49+
// expected-note@-2 {{remove 'async' and wrap in 'Task' to use concurrency in 'asyncIBAction'}}
50+
4851
}
4952

5053
struct S { }

0 commit comments

Comments
 (0)