@@ -1523,11 +1523,8 @@ static void fixAvailabilityForDecl(SourceRange ReferenceRange, const Decl *D,
1523
1523
// / version), emit a diagnostic and fixit that narrows the existing TRC
1524
1524
// / condition to the required range.
1525
1525
static bool fixAvailabilityByNarrowingNearbyVersionCheck (
1526
- SourceRange ReferenceRange,
1527
- const DeclContext *ReferenceDC,
1528
- const VersionRange &RequiredRange,
1529
- ASTContext &Context,
1530
- InFlightDiagnostic &Err) {
1526
+ SourceRange ReferenceRange, const DeclContext *ReferenceDC,
1527
+ const VersionRange &RequiredRange, ASTContext &Context) {
1531
1528
const TypeRefinementContext *TRC = nullptr ;
1532
1529
AvailabilityContext RunningOSOverApprox =
1533
1530
TypeChecker::overApproximateAvailabilityAtLocation (ReferenceRange.Start ,
@@ -1559,8 +1556,13 @@ static bool fixAvailabilityByNarrowingNearbyVersionCheck(
1559
1556
Platform, RunningVers);
1560
1557
if (!FixRange.isValid ())
1561
1558
return false ;
1559
+
1562
1560
// Have found a nontrivial type refinement context-introducer to narrow.
1563
- Err.fixItReplace (FixRange, RequiredVers.getAsString ());
1561
+ Context.Diags
1562
+ .diagnose (FixRange.Start ,
1563
+ diag::availability_narrow_nearby_version_check,
1564
+ RunningVers.getAsString (), RequiredVers.getAsString ())
1565
+ .fixItReplace (FixRange, RequiredVers.getAsString ());
1564
1566
return true ;
1565
1567
}
1566
1568
return false ;
@@ -1625,14 +1627,17 @@ static void fixAvailabilityByAddingVersionCheck(
1625
1627
}
1626
1628
1627
1629
// / Emit suggested Fix-Its for a reference with to an unavailable symbol
1628
- // / requiting the given OS version range.
1630
+ // / requiring the given OS version range.
1629
1631
static void fixAvailability (SourceRange ReferenceRange,
1630
1632
const DeclContext *ReferenceDC,
1631
1633
const VersionRange &RequiredRange,
1632
1634
ASTContext &Context) {
1633
1635
if (ReferenceRange.isInvalid ())
1634
1636
return ;
1635
1637
1638
+ fixAvailabilityByNarrowingNearbyVersionCheck (ReferenceRange, ReferenceDC,
1639
+ RequiredRange, Context);
1640
+
1636
1641
Optional<ASTNode> NodeToWrapInVersionCheck;
1637
1642
const Decl *FoundMemberDecl = nullptr ;
1638
1643
const Decl *FoundTypeLevelDecl = nullptr ;
@@ -1665,19 +1670,12 @@ void TypeChecker::diagnosePotentialOpaqueTypeUnavailability(
1665
1670
ASTContext &Context = ReferenceDC->getASTContext ();
1666
1671
1667
1672
auto RequiredRange = Reason.getRequiredOSVersionRange ();
1668
- {
1669
- auto Err =
1670
- Context.Diags .diagnose (
1671
- ReferenceRange.Start , diag::availability_opaque_types_only_version_newer,
1672
- prettyPlatformString (targetPlatform (Context.LangOpts )),
1673
- Reason.getRequiredOSVersionRange ().getLowerEndpoint ());
1674
-
1675
- // Direct a fixit to the error if an existing guard is nearly-correct
1676
- if (fixAvailabilityByNarrowingNearbyVersionCheck (ReferenceRange,
1677
- ReferenceDC,
1678
- RequiredRange, Context, Err))
1679
- return ;
1680
- }
1673
+
1674
+ Context.Diags .diagnose (ReferenceRange.Start ,
1675
+ diag::availability_opaque_types_only_version_newer,
1676
+ prettyPlatformString (targetPlatform (Context.LangOpts )),
1677
+ RequiredRange.getLowerEndpoint ());
1678
+
1681
1679
fixAvailability (ReferenceRange, ReferenceDC, RequiredRange, Context);
1682
1680
}
1683
1681
@@ -1687,20 +1685,12 @@ static void diagnosePotentialConcurrencyUnavailability(
1687
1685
ASTContext &Context = ReferenceDC->getASTContext ();
1688
1686
1689
1687
auto RequiredRange = Reason.getRequiredOSVersionRange ();
1690
- {
1691
- auto Err =
1692
- Context.Diags .diagnose (
1693
- ReferenceRange.Start ,
1694
- diag::availability_concurrency_only_version_newer,
1695
- prettyPlatformString (targetPlatform (Context.LangOpts )),
1696
- Reason.getRequiredOSVersionRange ().getLowerEndpoint ());
1697
-
1698
- // Direct a fixit to the error if an existing guard is nearly-correct
1699
- if (fixAvailabilityByNarrowingNearbyVersionCheck (ReferenceRange,
1700
- ReferenceDC,
1701
- RequiredRange, Context, Err))
1702
- return ;
1703
- }
1688
+
1689
+ Context.Diags .diagnose (ReferenceRange.Start ,
1690
+ diag::availability_concurrency_only_version_newer,
1691
+ prettyPlatformString (targetPlatform (Context.LangOpts )),
1692
+ RequiredRange.getLowerEndpoint ());
1693
+
1704
1694
fixAvailability (ReferenceRange, ReferenceDC, RequiredRange, Context);
1705
1695
}
1706
1696
@@ -1729,19 +1719,11 @@ void TypeChecker::diagnosePotentialUnavailability(
1729
1719
ASTContext &Context = ReferenceDC->getASTContext ();
1730
1720
1731
1721
auto RequiredRange = Reason.getRequiredOSVersionRange ();
1732
- {
1733
- auto Err =
1734
- Context.Diags .diagnose (
1735
- ReferenceRange.Start , diag::availability_decl_only_version_newer,
1736
- D->getName (), prettyPlatformString (targetPlatform (Context.LangOpts )),
1737
- Reason.getRequiredOSVersionRange ().getLowerEndpoint ());
1738
-
1739
- // Direct a fixit to the error if an existing guard is nearly-correct
1740
- if (fixAvailabilityByNarrowingNearbyVersionCheck (ReferenceRange,
1741
- ReferenceDC,
1742
- RequiredRange, Context, Err))
1743
- return ;
1744
- }
1722
+
1723
+ Context.Diags .diagnose (
1724
+ ReferenceRange.Start , diag::availability_decl_only_version_newer,
1725
+ D->getName (), prettyPlatformString (targetPlatform (Context.LangOpts )),
1726
+ RequiredRange.getLowerEndpoint ());
1745
1727
1746
1728
fixAvailability (ReferenceRange, ReferenceDC, RequiredRange, Context);
1747
1729
}
@@ -1757,25 +1739,15 @@ void TypeChecker::diagnosePotentialAccessorUnavailability(
1757
1739
const AbstractStorageDecl *ASD = Accessor->getStorage ();
1758
1740
DeclName Name = ASD->getName ();
1759
1741
1742
+ auto RequiredRange = Reason.getRequiredOSVersionRange ();
1760
1743
auto &diag = ForInout ? diag::availability_inout_accessor_only_version_newer
1761
1744
: diag::availability_accessor_only_version_newer;
1762
1745
1763
- auto RequiredRange = Reason.getRequiredOSVersionRange ();
1764
- {
1765
- auto Err =
1766
- Context.Diags .diagnose (
1767
- ReferenceRange.Start , diag,
1768
- static_cast <unsigned >(Accessor->getAccessorKind ()), Name,
1769
- prettyPlatformString (targetPlatform (Context.LangOpts )),
1770
- Reason.getRequiredOSVersionRange ().getLowerEndpoint ());
1771
-
1772
-
1773
- // Direct a fixit to the error if an existing guard is nearly-correct
1774
- if (fixAvailabilityByNarrowingNearbyVersionCheck (ReferenceRange,
1775
- ReferenceDC,
1776
- RequiredRange, Context, Err))
1777
- return ;
1778
- }
1746
+ Context.Diags .diagnose (ReferenceRange.Start , diag,
1747
+ static_cast <unsigned >(Accessor->getAccessorKind ()),
1748
+ Name,
1749
+ prettyPlatformString (targetPlatform (Context.LangOpts )),
1750
+ RequiredRange.getLowerEndpoint ());
1779
1751
1780
1752
fixAvailability (ReferenceRange, ReferenceDC, RequiredRange, Context);
1781
1753
}
@@ -1797,36 +1769,30 @@ behaviorLimitForExplicitUnavailability(
1797
1769
}
1798
1770
1799
1771
void TypeChecker::diagnosePotentialUnavailability (
1800
- const RootProtocolConformance *rootConf,
1801
- const ExtensionDecl *ext,
1802
- SourceLoc loc,
1803
- const DeclContext *dc,
1804
- const UnavailabilityReason &reason) {
1805
- ASTContext &ctx = dc->getASTContext ();
1772
+ const RootProtocolConformance *rootConf, const ExtensionDecl *ext,
1773
+ SourceLoc loc, const DeclContext *ReferenceDC,
1774
+ const UnavailabilityReason &Reason) {
1775
+ ASTContext &Context = ReferenceDC->getASTContext ();
1806
1776
1807
- auto requiredRange = reason .getRequiredOSVersionRange ();
1777
+ auto RequiredRange = Reason .getRequiredOSVersionRange ();
1808
1778
{
1809
1779
auto type = rootConf->getType ();
1810
1780
auto proto = rootConf->getProtocol ()->getDeclaredInterfaceType ();
1811
1781
1812
- auto diagID = (ctx.LangOpts .EnableConformanceAvailabilityErrors
1813
- ? diag::conformance_availability_only_version_newer
1814
- : diag::conformance_availability_only_version_newer_warn);
1815
- auto behavior = behaviorLimitForExplicitUnavailability (rootConf, dc);
1816
- auto err =
1817
- ctx.Diags .diagnose (
1818
- loc, diagID,
1819
- type, proto, prettyPlatformString (targetPlatform (ctx.LangOpts )),
1820
- reason.getRequiredOSVersionRange ().getLowerEndpoint ());
1782
+ const auto &diag =
1783
+ (Context.LangOpts .EnableConformanceAvailabilityErrors
1784
+ ? diag::conformance_availability_only_version_newer
1785
+ : diag::conformance_availability_only_version_newer_warn);
1786
+ auto behavior =
1787
+ behaviorLimitForExplicitUnavailability (rootConf, ReferenceDC);
1788
+ auto err = Context.Diags .diagnose (
1789
+ loc, diag, type, proto,
1790
+ prettyPlatformString (targetPlatform (Context.LangOpts )),
1791
+ RequiredRange.getLowerEndpoint ());
1821
1792
err.limitBehavior (behavior);
1822
-
1823
- // Direct a fixit to the error if an existing guard is nearly-correct
1824
- if (fixAvailabilityByNarrowingNearbyVersionCheck (loc, dc,
1825
- requiredRange, ctx, err))
1826
- return ;
1827
1793
}
1828
1794
1829
- fixAvailability (loc, dc, requiredRange, ctx );
1795
+ fixAvailability (loc, ReferenceDC, RequiredRange, Context );
1830
1796
}
1831
1797
1832
1798
const AvailableAttr *TypeChecker::getDeprecated (const Decl *D) {
0 commit comments