mirror of
https://github.com/apple/swift.git
synced 2025-12-14 20:36:38 +01:00
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.
This commit is contained in:
@@ -1433,8 +1433,6 @@ ERROR(invalid_ibinspectable,none,
|
||||
"only instance properties can be declared @%0", (StringRef))
|
||||
ERROR(invalid_ibaction_decl,none,
|
||||
"only instance methods can be declared @%0", (StringRef))
|
||||
ERROR(invalid_ibaction_decl_async,none,
|
||||
"@%0 instance methods cannot be async", (StringRef))
|
||||
ERROR(invalid_ibaction_result,none,
|
||||
"methods declared @%0 must %select{|not }1return a value", (StringRef, bool))
|
||||
ERROR(invalid_ibaction_argument_count,none,
|
||||
@@ -1466,11 +1464,12 @@ ERROR(cdecl_empty_name,none,
|
||||
"@_cdecl symbol name cannot be empty", ())
|
||||
ERROR(cdecl_throws,none,
|
||||
"raising errors from @_cdecl functions is not supported", ())
|
||||
ERROR(cdecl_async,none,
|
||||
"@_cdecl functions cannot be asynchronous", ())
|
||||
|
||||
ERROR(attr_methods_only,none,
|
||||
"only methods can be declared %0", (DeclAttribute))
|
||||
ERROR(attr_decl_async,none,
|
||||
"@%0 %1 cannot be asynchronous", (StringRef, DescriptiveDeclKind))
|
||||
|
||||
ERROR(access_control_in_protocol,none,
|
||||
"%0 modifier cannot be used in protocols", (DeclAttribute))
|
||||
NOTE(access_control_in_protocol_detail,none,
|
||||
|
||||
@@ -501,6 +501,12 @@ validateIBActionSignature(ASTContext &ctx, DeclAttribute *attr,
|
||||
valid = false;
|
||||
}
|
||||
|
||||
if (FD->isAsyncContext()) {
|
||||
ctx.Diags.diagnose(FD->getAsyncLoc(), diag::attr_decl_async,
|
||||
attr->getAttrName(), FD->getDescriptiveKind());
|
||||
valid = false;
|
||||
}
|
||||
|
||||
// We don't need to check here that parameter or return types are
|
||||
// ObjC-representable; IsObjCRequest will validate that.
|
||||
|
||||
@@ -530,12 +536,6 @@ void AttributeChecker::visitIBActionAttr(IBActionAttr *attr) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (FD->isAsyncContext()) {
|
||||
diagnoseAndRemoveAttr(attr, diag::invalid_ibaction_decl_async,
|
||||
attr->getAttrName());
|
||||
return;
|
||||
}
|
||||
|
||||
if (isRelaxedIBAction(Ctx))
|
||||
// iOS, tvOS, and watchOS allow 0-2 parameters to an @IBAction method.
|
||||
validateIBActionSignature(Ctx, attr, FD, /*minParams=*/0, /*maxParams=*/2);
|
||||
|
||||
@@ -2973,7 +2973,9 @@ public:
|
||||
if (FD->hasAsync()) {
|
||||
FD->setForeignAsyncConvention(*asyncConvention);
|
||||
getASTContext().Diags.diagnose(CDeclAttr->getLocation(),
|
||||
diag::cdecl_async);
|
||||
diag::attr_decl_async,
|
||||
CDeclAttr->getAttrName(),
|
||||
FD->getDescriptiveKind());
|
||||
} else if (FD->hasThrows()) {
|
||||
FD->setForeignErrorConvention(*errorConvention);
|
||||
getASTContext().Diags.diagnose(CDeclAttr->getLocation(),
|
||||
|
||||
@@ -2,6 +2,6 @@
|
||||
|
||||
// REQUIRES: concurrency
|
||||
|
||||
@_cdecl("async") // expected-error{{@_cdecl functions cannot be asynchronous}}
|
||||
@_cdecl("async") // expected-error{{@_cdecl global function cannot be asynchronous}}
|
||||
func asynchronous() async { }
|
||||
|
||||
|
||||
@@ -43,7 +43,7 @@ class IBActionWrapperTy {
|
||||
func evenMoreMagic(_: AnyObject) -> () {} // no-warning
|
||||
|
||||
@available(macOS 10.15, *)
|
||||
@IBAction // expected-error {{@IBAction instance methods cannot be async}}
|
||||
@IBAction // expected-error@+1 {{@IBAction instance method cannot be async}}
|
||||
func asyncIBAction(_: AnyObject) async -> () {}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user