@@ -1779,6 +1779,22 @@ void TypeChecker::diagnosePotentialAccessorUnavailability(
1779
1779
fixAvailability (ReferenceRange, ReferenceDC, RequiredRange, Context);
1780
1780
}
1781
1781
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
+
1782
1798
void TypeChecker::diagnosePotentialUnavailability (
1783
1799
const RootProtocolConformance *rootConf,
1784
1800
const ExtensionDecl *ext,
@@ -1795,11 +1811,13 @@ void TypeChecker::diagnosePotentialUnavailability(
1795
1811
auto diagID = (ctx.LangOpts .EnableConformanceAvailabilityErrors
1796
1812
? diag::conformance_availability_only_version_newer
1797
1813
: diag::conformance_availability_only_version_newer_warn);
1814
+ auto behavior = behaviorLimitForExplicitUnavailability (rootConf, dc);
1798
1815
auto err =
1799
1816
ctx.Diags .diagnose (
1800
1817
loc, diagID,
1801
1818
type, proto, prettyPlatformString (targetPlatform (ctx.LangOpts )),
1802
1819
reason.getRequiredOSVersionRange ().getLowerEndpoint ());
1820
+ err.limitBehavior (behavior);
1803
1821
1804
1822
// Direct a fixit to the error if an existing guard is nearly-correct
1805
1823
if (fixAvailabilityByNarrowingNearbyVersionCheck (loc, dc,
@@ -2422,31 +2440,6 @@ bool swift::diagnoseExplicitUnavailability(const ValueDecl *D, SourceRange R,
2422
2440
});
2423
2441
}
2424
2442
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
-
2450
2443
// / Emit a diagnostic for references to declarations that have been
2451
2444
// / marked as unavailable, either through "unavailable" or "obsoleted:".
2452
2445
bool swift::diagnoseExplicitUnavailability (SourceLoc loc,
@@ -2482,11 +2475,12 @@ bool swift::diagnoseExplicitUnavailability(SourceLoc loc,
2482
2475
// This was platform-specific; indicate the platform.
2483
2476
platform = attr->prettyPlatformString ();
2484
2477
break ;
2485
- } else {
2486
- // Downgrade unavailable Sendable conformances to warnings prior to
2487
- // Swift 6.
2488
- behavior = behaviorLimitForExplicitUnavailability (rootConf);
2489
2478
}
2479
+
2480
+ // Downgrade unavailable Sendable conformance diagnostics where
2481
+ // appropriate.
2482
+ behavior = behaviorLimitForExplicitUnavailability (
2483
+ rootConf, where.getDeclContext ());
2490
2484
LLVM_FALLTHROUGH;
2491
2485
2492
2486
case PlatformAgnosticAvailabilityKind::SwiftVersionSpecific:
0 commit comments