Skip to content

Commit 9045180

Browse files
committed
Sema: Diagnose @available attibutes that cannot be noasync.
Instead of asserting.
1 parent bd79424 commit 9045180

File tree

2 files changed

+21
-4
lines changed

2 files changed

+21
-4
lines changed

lib/Sema/TypeCheckAttr.cpp

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -8298,18 +8298,25 @@ SemanticAvailableAttrRequest::evaluate(swift::Evaluator &evaluator,
82988298
}
82998299

83008300
if (domain->isSwiftLanguage() || domain->isPackageDescription()) {
8301-
if (attrKind == AvailableAttr::Kind::Deprecated) {
8301+
switch (attrKind) {
8302+
case AvailableAttr::Kind::Deprecated:
83028303
diags.diagnose(attrLoc,
83038304
diag::attr_availability_expected_deprecated_version,
83048305
attrName, *string);
83058306
return std::nullopt;
8306-
}
8307-
if (attrKind == AvailableAttr::Kind::Unavailable) {
8307+
8308+
case AvailableAttr::Kind::Unavailable:
83088309
diags.diagnose(attrLoc, diag::attr_availability_cannot_be_used_for_domain,
83098310
"unavailable", attrName, *string);
83108311
return std::nullopt;
8312+
8313+
case AvailableAttr::Kind::NoAsync:
8314+
diags.diagnose(attrLoc, diag::attr_availability_cannot_be_used_for_domain,
8315+
"noasync", attrName, *string);
8316+
break;
8317+
case AvailableAttr::Kind::Default:
8318+
break;
83118319
}
8312-
assert(attrKind == AvailableAttr::Kind::Default);
83138320

83148321
bool hasVersionSpec = (attr->getRawIntroduced() ||
83158322
attr->getRawDeprecated() || attr->getRawObsoleted());

test/attr/attr_availability_noasync.swift

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,16 @@ func asyncReplacement() async -> Int { }
1818
@available(*, noasync, renamed: "IOActor.readString()")
1919
func readStringFromIO() -> String {}
2020

21+
// expected-warning@+2 {{'noasync' cannot be used in 'available' attribute for platform 'swift'}}
22+
// expected-warning@+1 {{expected 'introduced', 'deprecated', or 'obsoleted' in 'available' attribute for platform 'swift'}}
23+
@available(swift, noasync)
24+
func swiftNoAsync() { }
25+
26+
// expected-warning@+2 {{'noasync' cannot be used in 'available' attribute for platform '_PackageDescription'}}
27+
// expected-warning@+1 {{expected 'introduced', 'deprecated', or 'obsoleted' in 'available' attribute for platform '_PackageDescription'}}
28+
@available(_PackageDescription, noasync)
29+
func packageDescriptionNoAsync() { }
30+
2131
@available(SwiftStdlib 5.5, *)
2232
actor IOActor {
2333
func readString() -> String {

0 commit comments

Comments
 (0)