Skip to content

Commit fad7453

Browse files
committed
Merge invalid async decl + attribute
This patch merges the two diagnostics complaining about asynchronous function declarations with incompatible attributes. The two are cdecl and ibaction at the moment.
1 parent 93a2b6f commit fad7453

File tree

5 files changed

+14
-13
lines changed

5 files changed

+14
-13
lines changed

include/swift/AST/DiagnosticsSema.def

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1433,8 +1433,6 @@ ERROR(invalid_ibinspectable,none,
14331433
"only instance properties can be declared @%0", (StringRef))
14341434
ERROR(invalid_ibaction_decl,none,
14351435
"only instance methods can be declared @%0", (StringRef))
1436-
ERROR(invalid_ibaction_decl_async,none,
1437-
"@%0 instance methods cannot be async", (StringRef))
14381436
ERROR(invalid_ibaction_result,none,
14391437
"methods declared @%0 must %select{|not }1return a value", (StringRef, bool))
14401438
ERROR(invalid_ibaction_argument_count,none,
@@ -1466,11 +1464,12 @@ ERROR(cdecl_empty_name,none,
14661464
"@_cdecl symbol name cannot be empty", ())
14671465
ERROR(cdecl_throws,none,
14681466
"raising errors from @_cdecl functions is not supported", ())
1469-
ERROR(cdecl_async,none,
1470-
"@_cdecl functions cannot be asynchronous", ())
14711467

14721468
ERROR(attr_methods_only,none,
14731469
"only methods can be declared %0", (DeclAttribute))
1470+
ERROR(attr_decl_async,none,
1471+
"@%0 %1 cannot be asynchronous", (StringRef, DescriptiveDeclKind))
1472+
14741473
ERROR(access_control_in_protocol,none,
14751474
"%0 modifier cannot be used in protocols", (DeclAttribute))
14761475
NOTE(access_control_in_protocol_detail,none,

lib/Sema/TypeCheckAttr.cpp

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -501,6 +501,12 @@ validateIBActionSignature(ASTContext &ctx, DeclAttribute *attr,
501501
valid = false;
502502
}
503503

504+
if (FD->isAsyncContext()) {
505+
ctx.Diags.diagnose(FD->getAsyncLoc(), diag::attr_decl_async,
506+
attr->getAttrName(), FD->getDescriptiveKind());
507+
valid = false;
508+
}
509+
504510
// We don't need to check here that parameter or return types are
505511
// ObjC-representable; IsObjCRequest will validate that.
506512

@@ -530,12 +536,6 @@ void AttributeChecker::visitIBActionAttr(IBActionAttr *attr) {
530536
return;
531537
}
532538

533-
if (FD->isAsyncContext()) {
534-
diagnoseAndRemoveAttr(attr, diag::invalid_ibaction_decl_async,
535-
attr->getAttrName());
536-
return;
537-
}
538-
539539
if (isRelaxedIBAction(Ctx))
540540
// iOS, tvOS, and watchOS allow 0-2 parameters to an @IBAction method.
541541
validateIBActionSignature(Ctx, attr, FD, /*minParams=*/0, /*maxParams=*/2);

lib/Sema/TypeCheckDeclPrimary.cpp

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2973,7 +2973,9 @@ class DeclChecker : public DeclVisitor<DeclChecker> {
29732973
if (FD->hasAsync()) {
29742974
FD->setForeignAsyncConvention(*asyncConvention);
29752975
getASTContext().Diags.diagnose(CDeclAttr->getLocation(),
2976-
diag::cdecl_async);
2976+
diag::attr_decl_async,
2977+
CDeclAttr->getAttrName(),
2978+
FD->getDescriptiveKind());
29772979
} else if (FD->hasThrows()) {
29782980
FD->setForeignErrorConvention(*errorConvention);
29792981
getASTContext().Diags.diagnose(CDeclAttr->getLocation(),

test/attr/attr_cdecl_async.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,6 @@
22

33
// REQUIRES: concurrency
44

5-
@_cdecl("async") // expected-error{{@_cdecl functions cannot be asynchronous}}
5+
@_cdecl("async") // expected-error{{@_cdecl global function cannot be asynchronous}}
66
func asynchronous() async { }
77

test/attr/attr_ibaction.swift

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

4545
@available(macOS 10.15, *)
46-
@IBAction // expected-error {{@IBAction instance methods cannot be async}}
46+
@IBAction // expected-error@+1 {{@IBAction instance method cannot be async}}
4747
func asyncIBAction(_: AnyObject) async -> () {}
4848
}
4949

0 commit comments

Comments
 (0)