@@ -1779,6 +1779,22 @@ void TypeChecker::diagnosePotentialAccessorUnavailability(
17791779 fixAvailability (ReferenceRange, ReferenceDC, RequiredRange, Context);
17801780}
17811781
1782+ static DiagnosticBehavior
1783+ behaviorLimitForExplicitUnavailability (
1784+ const RootProtocolConformance *rootConf,
1785+ const DeclContext *fromDC) {
1786+ auto protoDecl = rootConf->getProtocol ();
1787+
1788+ // Soften errors about unavailable `Sendable` conformances depending on the
1789+ // concurrency checking mode
1790+ if (protoDecl->isSpecificProtocol (KnownProtocolKind::Sendable) ||
1791+ protoDecl->isSpecificProtocol (KnownProtocolKind::UnsafeSendable)) {
1792+ return SendableCheckContext (fromDC).defaultDiagnosticBehavior ();
1793+ }
1794+
1795+ return DiagnosticBehavior::Unspecified;
1796+ }
1797+
17821798void TypeChecker::diagnosePotentialUnavailability (
17831799 const RootProtocolConformance *rootConf,
17841800 const ExtensionDecl *ext,
@@ -1795,11 +1811,13 @@ void TypeChecker::diagnosePotentialUnavailability(
17951811 auto diagID = (ctx.LangOpts .EnableConformanceAvailabilityErrors
17961812 ? diag::conformance_availability_only_version_newer
17971813 : diag::conformance_availability_only_version_newer_warn);
1814+ auto behavior = behaviorLimitForExplicitUnavailability (rootConf, dc);
17981815 auto err =
17991816 ctx.Diags .diagnose (
18001817 loc, diagID,
18011818 type, proto, prettyPlatformString (targetPlatform (ctx.LangOpts )),
18021819 reason.getRequiredOSVersionRange ().getLowerEndpoint ());
1820+ err.limitBehavior (behavior);
18031821
18041822 // Direct a fixit to the error if an existing guard is nearly-correct
18051823 if (fixAvailabilityByNarrowingNearbyVersionCheck (loc, dc,
@@ -2422,31 +2440,6 @@ bool swift::diagnoseExplicitUnavailability(const ValueDecl *D, SourceRange R,
24222440 });
24232441}
24242442
2425- static DiagnosticBehavior
2426- behaviorLimitForExplicitUnavailability (const RootProtocolConformance *rootConf) {
2427- auto protoDecl = rootConf->getProtocol ();
2428-
2429- // Soften errors about unavailable `Sendable` conformances depending on the
2430- // concurrency checking mode
2431- if (protoDecl->isSpecificProtocol (KnownProtocolKind::Sendable) ||
2432- protoDecl->isSpecificProtocol (KnownProtocolKind::UnsafeSendable)) {
2433- // TODO: Base this on concurrency checking mode from ExportContext so it
2434- // detects when you're in concurrency code without -warn-concurrency.
2435- auto &langOpts = protoDecl->getASTContext ().LangOpts ;
2436- if (langOpts.isSwiftVersionAtLeast (6 ))
2437- /* fall through */ ;
2438- else if (!langOpts.WarnConcurrency )
2439- // TODO: Needs more conditions--should only do this if we aren't in a
2440- // concurrent context, and either the import or the declaration is
2441- // @predatesConcurrency.
2442- return DiagnosticBehavior::Ignore;
2443- else
2444- return DiagnosticBehavior::Warning;
2445- }
2446-
2447- return DiagnosticBehavior::Unspecified;
2448- }
2449-
24502443// / Emit a diagnostic for references to declarations that have been
24512444// / marked as unavailable, either through "unavailable" or "obsoleted:".
24522445bool swift::diagnoseExplicitUnavailability (SourceLoc loc,
@@ -2482,11 +2475,12 @@ bool swift::diagnoseExplicitUnavailability(SourceLoc loc,
24822475 // This was platform-specific; indicate the platform.
24832476 platform = attr->prettyPlatformString ();
24842477 break ;
2485- } else {
2486- // Downgrade unavailable Sendable conformances to warnings prior to
2487- // Swift 6.
2488- behavior = behaviorLimitForExplicitUnavailability (rootConf);
24892478 }
2479+
2480+ // Downgrade unavailable Sendable conformance diagnostics where
2481+ // appropriate.
2482+ behavior = behaviorLimitForExplicitUnavailability (
2483+ rootConf, where.getDeclContext ());
24902484 LLVM_FALLTHROUGH;
24912485
24922486 case PlatformAgnosticAvailabilityKind::SwiftVersionSpecific:
0 commit comments