@@ -1465,61 +1465,6 @@ AvailabilityRange TypeChecker::overApproximateAvailabilityAtLocation(
1465
1465
return availabilityAtLocation (loc, DC, MostRefined).getPlatformRange ();
1466
1466
}
1467
1467
1468
- static bool isDeclarationUnavailable (
1469
- const Decl *D, const DeclContext *referenceDC,
1470
- llvm::function_ref<AvailabilityRange()> getAvailabilityRange) {
1471
- ASTContext &Context = referenceDC->getASTContext ();
1472
- if (Context.LangOpts .DisableAvailabilityChecking ) {
1473
- return false ;
1474
- }
1475
-
1476
- if (!referenceDC->getParentSourceFile ()) {
1477
- // We only check availability if this reference is in a source file; we do
1478
- // not check in other kinds of FileUnits.
1479
- return false ;
1480
- }
1481
-
1482
- AvailabilityRange safeRangeUnderApprox{
1483
- AvailabilityInference::availableRange (D)};
1484
-
1485
- if (safeRangeUnderApprox.isAlwaysAvailable ())
1486
- return false ;
1487
-
1488
- AvailabilityRange runningOSOverApprox = getAvailabilityRange ();
1489
-
1490
- // The reference is safe if an over-approximation of the running OS
1491
- // versions is fully contained within an under-approximation
1492
- // of the versions on which the declaration is available. If this
1493
- // containment cannot be guaranteed, we say the reference is
1494
- // not available.
1495
- return !runningOSOverApprox.isContainedIn (safeRangeUnderApprox);
1496
- }
1497
-
1498
- static std::optional<AvailabilityRange>
1499
- checkDeclarationAvailability (const Decl *D, const ExportContext &Where) {
1500
- // Skip computing potential unavailability if the declaration is explicitly
1501
- // unavailable and the context is also unavailable.
1502
- if (const AvailableAttr *Attr = AvailableAttr::isUnavailable (D))
1503
- if (isInsideCompatibleUnavailableDeclaration (D, Where.getAvailability (),
1504
- Attr))
1505
- return std::nullopt;
1506
-
1507
- if (isDeclarationUnavailable (D, Where.getDeclContext (), [&Where] {
1508
- return Where.getAvailabilityRange ();
1509
- })) {
1510
- return AvailabilityInference::availableRange (D);
1511
- }
1512
-
1513
- return std::nullopt;
1514
- }
1515
-
1516
- std::optional<AvailabilityRange>
1517
- TypeChecker::checkConformanceAvailability (const RootProtocolConformance *conf,
1518
- const ExtensionDecl *ext,
1519
- const ExportContext &where) {
1520
- return checkDeclarationAvailability (ext, where);
1521
- }
1522
-
1523
1468
// / A class that walks the AST to find the innermost (i.e., deepest) node that
1524
1469
// / contains a target SourceRange and matches a particular criterion.
1525
1470
// / This class finds the innermost nodes of interest by walking
@@ -2261,12 +2206,14 @@ behaviorLimitForExplicitUnavailability(
2261
2206
2262
2207
// / Emits a diagnostic for a protocol conformance that is potentially
2263
2208
// / unavailable at the given source location.
2264
- static void
2209
+ static bool
2265
2210
diagnosePotentialUnavailability (const RootProtocolConformance *rootConf,
2266
2211
const ExtensionDecl *ext, SourceLoc loc,
2267
2212
const DeclContext *dc,
2268
2213
const AvailabilityRange &availability) {
2269
2214
ASTContext &ctx = dc->getASTContext ();
2215
+ if (ctx.LangOpts .DisableAvailabilityChecking )
2216
+ return false ;
2270
2217
2271
2218
{
2272
2219
auto type = rootConf->getType ();
@@ -2282,10 +2229,11 @@ diagnosePotentialUnavailability(const RootProtocolConformance *rootConf,
2282
2229
// Direct a fixit to the error if an existing guard is nearly-correct
2283
2230
if (fixAvailabilityByNarrowingNearbyVersionCheck (loc, dc, availability, ctx,
2284
2231
err))
2285
- return ;
2232
+ return true ;
2286
2233
}
2287
2234
2288
2235
fixAvailability (loc, dc, availability, ctx);
2236
+ return true ;
2289
2237
}
2290
2238
2291
2239
// / Returns the availability attribute indicating deprecation of the
@@ -4625,6 +4573,7 @@ swift::diagnoseConformanceAvailability(SourceLoc loc,
4625
4573
// Diagnose "missing" conformances where we needed a conformance but
4626
4574
// didn't have one.
4627
4575
auto *DC = where.getDeclContext ();
4576
+ auto &ctx = DC->getASTContext ();
4628
4577
if (auto builtinConformance = dyn_cast<BuiltinProtocolConformance>(rootConf)){
4629
4578
if (builtinConformance->isMissing ()) {
4630
4579
diagnoseMissingConformance (loc, builtinConformance->getType (),
@@ -4638,7 +4587,6 @@ swift::diagnoseConformanceAvailability(SourceLoc loc,
4638
4587
4639
4588
Type selfTy = rootConf->getProtocol ()->getSelfInterfaceType ();
4640
4589
if (!depTy->isEqual (selfTy)) {
4641
- auto &ctx = DC->getASTContext ();
4642
4590
ctx.Diags .diagnose (
4643
4591
loc,
4644
4592
diag::assoc_conformance_from_implementation_only_module,
@@ -4653,20 +4601,26 @@ swift::diagnoseConformanceAvailability(SourceLoc loc,
4653
4601
return true ;
4654
4602
}
4655
4603
4656
- if (diagnoseExplicitUnavailability (loc, rootConf, ext, where,
4657
- warnIfConformanceUnavailablePreSwift6)) {
4658
- maybeEmitAssociatedTypeNote ();
4659
- return true ;
4660
- }
4604
+ auto unmetRequirement = getUnmetDeclAvailabilityRequirement (
4605
+ ext, where.getDeclContext (), where.getAvailability ());
4606
+ if (unmetRequirement) {
4607
+ // FIXME: diagnoseExplicitUnavailability() should take unmet requirement
4608
+ if (diagnoseExplicitUnavailability (
4609
+ loc, rootConf, ext, where,
4610
+ warnIfConformanceUnavailablePreSwift6)) {
4611
+ maybeEmitAssociatedTypeNote ();
4612
+ return true ;
4613
+ }
4661
4614
4662
- // Diagnose (and possibly signal) for potential unavailability
4663
- auto maybeUnavail = TypeChecker::checkConformanceAvailability (
4664
- rootConf, ext, where);
4665
- if (maybeUnavail.has_value ()) {
4666
- diagnosePotentialUnavailability (rootConf, ext, loc, DC,
4667
- maybeUnavail.value ());
4668
- maybeEmitAssociatedTypeNote ();
4669
- return true ;
4615
+ // Diagnose (and possibly signal) for potential unavailability
4616
+ if (auto requiredRange =
4617
+ unmetRequirement->getRequiredNewerAvailabilityRange (ctx)) {
4618
+ if (diagnosePotentialUnavailability (rootConf, ext, loc, DC,
4619
+ *requiredRange)) {
4620
+ maybeEmitAssociatedTypeNote ();
4621
+ return true ;
4622
+ }
4623
+ }
4670
4624
}
4671
4625
4672
4626
// Diagnose for deprecation
0 commit comments