[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.
This commit is contained in:
Pavel Yaskevich
2025-01-17 14:01:34 -08:00
parent 6b2fb2e4b4
commit 00fe5632d7
2 changed files with 22 additions and 0 deletions

View File

@@ -4147,6 +4147,8 @@ diagnoseDeclAsyncAvailability(const ValueDecl *D, SourceRange R,
auto diag = ctx.Diags.diagnose(diagLoc, diag::async_unavailable_decl, D,
attr->getMessage());
diag.warnUntilSwiftVersion(6);
diag.limitBehaviorWithPreconcurrency(DiagnosticBehavior::Warning,
D->preconcurrency());
if (!attr->getRename().empty()) {
fixItAvailableAttrRename(diag, R, D, attr->getRename(), call);

View File

@@ -0,0 +1,20 @@
// RUN: %target-typecheck-verify-swift -target %target-swift-5.1-abi-triple -swift-version 6
// REQUIRES: concurrency
// REQUIRES: asserts
struct API {
@available(*, noasync, message: "use complete() instead")
func wait() {}
@preconcurrency
@available(*, noasync, message: "use complete() instead")
func waitUntilComplete() {}
func complete() async {}
}
func test(v: API) async {
v.wait() // expected-error {{instance method 'wait' is unavailable from asynchronous contexts; use complete() instead}}
v.waitUntilComplete() // expected-warning {{instance method 'waitUntilComplete' is unavailable from asynchronous contexts; use complete() instead}}
}