Skip to content

Commit 65af4bb

Browse files
committed
[TypeChecker] Downgrade noasync availability to warnings on @preconcurrency declarations
This change helps to stage in new `async` overloads in Swift 6 language mode if `@preconcurrency` declaration is not available from async contexts. (cherry picked from commit 00fe563)
1 parent ecdbbd5 commit 65af4bb

File tree

2 files changed

+22
-0
lines changed

2 files changed

+22
-0
lines changed

lib/Sema/TypeCheckAvailability.cpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4128,6 +4128,8 @@ diagnoseDeclAsyncAvailability(const ValueDecl *D, SourceRange R,
41284128
auto diag = ctx.Diags.diagnose(diagLoc, diag::async_unavailable_decl,
41294129
D, attr->Message);
41304130
diag.warnUntilSwiftVersion(6);
4131+
diag.limitBehaviorWithPreconcurrency(DiagnosticBehavior::Warning,
4132+
D->preconcurrency());
41314133

41324134
if (!attr->Rename.empty()) {
41334135
fixItAvailableAttrRename(diag, R, D, attr, call);
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
// RUN: %target-typecheck-verify-swift -target %target-swift-5.1-abi-triple -swift-version 6
2+
3+
// REQUIRES: concurrency
4+
// REQUIRES: asserts
5+
6+
struct API {
7+
@available(*, noasync, message: "use complete() instead")
8+
func wait() {}
9+
10+
@preconcurrency
11+
@available(*, noasync, message: "use complete() instead")
12+
func waitUntilComplete() {}
13+
14+
func complete() async {}
15+
}
16+
17+
func test(v: API) async {
18+
v.wait() // expected-error {{instance method 'wait' is unavailable from asynchronous contexts; use complete() instead}}
19+
v.waitUntilComplete() // expected-warning {{instance method 'waitUntilComplete' is unavailable from asynchronous contexts; use complete() instead}}
20+
}

0 commit comments

Comments
 (0)