From fcf6ed7fba2669517bc91188cfeb070388c9a917 Mon Sep 17 00:00:00 2001 From: Holly Borla Date: Thu, 18 Jul 2024 20:44:28 -0700 Subject: [PATCH] [Concurrency] Don't warn about re-stating inherited unavailable conformances to `Sendable`. The unavailability check was not using the root conformance, which is where the extension declaration with the unavailability attribute is for inherited conformances, leading to bogus warnings about re-stating unchecked conformances to `Sendable`. (cherry picked from commit 69b2435babc7d0424b59be3ead52e05a12a2a072) --- lib/Sema/TypeCheckConcurrency.cpp | 6 +++++- test/Concurrency/concurrent_value_checking.swift | 8 ++++++++ 2 files changed, 13 insertions(+), 1 deletion(-) diff --git a/lib/Sema/TypeCheckConcurrency.cpp b/lib/Sema/TypeCheckConcurrency.cpp index 3c61f01bfd987..b116b1a432086 100644 --- a/lib/Sema/TypeCheckConcurrency.cpp +++ b/lib/Sema/TypeCheckConcurrency.cpp @@ -6186,7 +6186,11 @@ bool swift::checkSendableConformance( return false; // If this is an always-unavailable conformance, there's nothing to check. - if (auto ext = dyn_cast(conformanceDC)) { + // We always use the root conformance for this check, because inherited + // conformances need to walk back to the original declaration for the + // superclass conformance to find an unavailable attribute. + if (auto ext = dyn_cast( + conformance->getRootConformance()->getDeclContext())) { if (AvailableAttr::isUnavailable(ext)) return false; } diff --git a/test/Concurrency/concurrent_value_checking.swift b/test/Concurrency/concurrent_value_checking.swift index 7d0f4c2ae22a6..57b0b6dfe79ed 100644 --- a/test/Concurrency/concurrent_value_checking.swift +++ b/test/Concurrency/concurrent_value_checking.swift @@ -380,6 +380,14 @@ final class C7: Sendable { } class C9: Sendable { } // expected-warning{{non-final class 'C9' cannot conform to 'Sendable'; use '@unchecked Sendable'}} +@available(*, unavailable) +extension HasUnavailableSendable : @unchecked Sendable { } + +class HasUnavailableSendable { +} + +class NoRestated: HasUnavailableSendable {} // okay + @globalActor struct SomeActor { static let shared = A1()