@@ -1333,6 +1333,7 @@ bool swift::fixItOverrideDeclarationTypes(TypeChecker &TC,
1333
1333
void swift::fixItAvailableAttrRename (TypeChecker &TC,
1334
1334
InFlightDiagnostic &diag,
1335
1335
SourceRange referenceRange,
1336
+ const ValueDecl *renamedDecl,
1336
1337
const AvailableAttr *attr,
1337
1338
const ApplyExpr *call) {
1338
1339
ParsedDeclName parsed = swift::parseDeclName (attr->Rename );
@@ -1487,6 +1488,12 @@ void swift::fixItAvailableAttrRename(TypeChecker &TC,
1487
1488
baseReplace += ' .' ;
1488
1489
}
1489
1490
baseReplace += parsed.BaseName ;
1491
+ if (parsed.IsFunctionName && parsed.ArgumentLabels .empty () &&
1492
+ isa<VarDecl>(renamedDecl)) {
1493
+ // If we're going from a var to a function with no arguments, emit an
1494
+ // empty parameter list.
1495
+ baseReplace += " ()" ;
1496
+ }
1490
1497
diag.fixItReplace (referenceRange, baseReplace);
1491
1498
}
1492
1499
@@ -1689,11 +1696,14 @@ describeRename(ASTContext &ctx, const AvailableAttr *attr, const ValueDecl *D,
1689
1696
return ReplacementDeclKind::None;
1690
1697
}
1691
1698
1692
- void TypeChecker::diagnoseDeprecated (SourceRange ReferenceRange,
1693
- const DeclContext *ReferenceDC,
1694
- const AvailableAttr *Attr,
1695
- DeclName Name,
1696
- const ApplyExpr *Call) {
1699
+ void TypeChecker::diagnoseIfDeprecated (SourceRange ReferenceRange,
1700
+ const DeclContext *ReferenceDC,
1701
+ const ValueDecl *DeprecatedDecl,
1702
+ const ApplyExpr *Call) {
1703
+ const AvailableAttr *Attr = TypeChecker::getDeprecated (DeprecatedDecl);
1704
+ if (!Attr)
1705
+ return ;
1706
+
1697
1707
// We match the behavior of clang to not report deprecation warnings
1698
1708
// inside declarations that are themselves deprecated on all deployment
1699
1709
// targets.
@@ -1712,6 +1722,7 @@ void TypeChecker::diagnoseDeprecated(SourceRange ReferenceRange,
1712
1722
}
1713
1723
}
1714
1724
1725
+ DeclName Name = DeprecatedDecl->getFullName ();
1715
1726
StringRef Platform = Attr->prettyPlatformString ();
1716
1727
clang::VersionTuple DeprecatedVersion;
1717
1728
if (Attr->Deprecated )
@@ -1750,7 +1761,8 @@ void TypeChecker::diagnoseDeprecated(SourceRange ReferenceRange,
1750
1761
auto renameDiag = diagnose (ReferenceRange.Start ,
1751
1762
diag::note_deprecated_rename,
1752
1763
newName);
1753
- fixItAvailableAttrRename (*this , renameDiag, ReferenceRange, Attr, Call);
1764
+ fixItAvailableAttrRename (*this , renameDiag, ReferenceRange, DeprecatedDecl,
1765
+ Attr, Call);
1754
1766
}
1755
1767
}
1756
1768
@@ -1806,7 +1818,7 @@ bool TypeChecker::diagnoseExplicitUnavailability(const ValueDecl *D,
1806
1818
const ApplyExpr *call) {
1807
1819
return diagnoseExplicitUnavailability (D, R, DC,
1808
1820
[=](InFlightDiagnostic &diag) {
1809
- fixItAvailableAttrRename (*this , diag, R, AvailableAttr::isUnavailable (D),
1821
+ fixItAvailableAttrRename (*this , diag, R, D, AvailableAttr::isUnavailable (D),
1810
1822
call);
1811
1823
});
1812
1824
}
@@ -2134,9 +2146,7 @@ bool AvailabilityWalker::diagAvailability(const ValueDecl *D, SourceRange R,
2134
2146
return true ;
2135
2147
2136
2148
// Diagnose for deprecation
2137
- if (const AvailableAttr *Attr = TypeChecker::getDeprecated (D)) {
2138
- TC.diagnoseDeprecated (R, DC, Attr, D->getFullName (), call);
2139
- }
2149
+ TC.diagnoseIfDeprecated (R, DC, D, call);
2140
2150
2141
2151
// Diagnose for potential unavailability
2142
2152
auto maybeUnavail = TC.checkDeclarationAvailability (D, R.Start , DC);
0 commit comments