Skip to content

Commit 9e8f8d9

Browse files
committed
centralized it a little better
1 parent d0c1fd6 commit 9e8f8d9

File tree

1 file changed

+13
-21
lines changed

1 file changed

+13
-21
lines changed

lib/Parse/ParseDecl.cpp

Lines changed: 13 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -1536,42 +1536,34 @@ bool Parser::parseDeclAttribute(DeclAttributes &Attributes, SourceLoc AtLoc) {
15361536
// If the attribute follows the new representation, switch
15371537
// over to the alternate parsing path.
15381538
DeclAttrKind DK = DeclAttribute::getAttrKindFromString(Tok.getText());
1539-
1540-
auto checkRenamedAttr = [&](StringRef oldName, StringRef newName,
1541-
DeclAttrKind kind, bool warning) {
1542-
if (DK == DAK_Count && Tok.getText() == oldName) {
1539+
1540+
auto checkInvalidAttrName = [&](StringRef invalidName, StringRef correctName,
1541+
DeclAttrKind kind, Diag<StringRef, StringRef> diag) {
1542+
if (DK == DAK_Count && Tok.getText() == invalidName) {
15431543
// We renamed @availability to @available, so if we see the former,
15441544
// treat it as the latter and emit a Fix-It.
15451545
DK = kind;
1546-
if (warning) {
1547-
diagnose(Tok, diag::attr_renamed_warning, oldName, newName)
1548-
.fixItReplace(Tok.getLoc(), newName);
1549-
} else {
1550-
diagnose(Tok, diag::attr_renamed, oldName, newName)
1551-
.fixItReplace(Tok.getLoc(), newName);
1552-
}
1546+
1547+
diagnose(Tok, diag, invalidName, correctName)
1548+
.fixItReplace(Tok.getLoc(), correctName);
15531549
}
15541550
};
15551551

15561552
// FIXME: This renaming happened before Swift 3, we can probably remove
15571553
// the specific fallback path at some point.
1558-
checkRenamedAttr("availability", "available", DAK_Available, false);
1554+
checkInvalidAttrName("availability", "available", DAK_Available, diag::attr_renamed);
15591555

15601556
// Check if attr is inlineable, and suggest inlinable instead
1561-
if (DK == DAK_Count && Tok.getText() == "inlineable") {
1562-
DK = DAK_Inlinable;
1563-
diagnose(Tok, diag::attr_name_close_match, "inlineable", "inlinable")
1564-
.fixItReplace(Tok.getLoc(), "inlinable");
1565-
}
1557+
checkInvalidAttrName("inlineable", "inlinable", DAK_Inlinable, diag::attr_name_close_match);
15661558

15671559
// In Swift 5 and above, these become hard errors. Otherwise, emit a
15681560
// warning for compatibility.
15691561
if (!Context.isSwiftVersionAtLeast(5)) {
1570-
checkRenamedAttr("_versioned", "usableFromInline", DAK_UsableFromInline, true);
1571-
checkRenamedAttr("_inlineable", "inlinable", DAK_Inlinable, true);
1562+
checkInvalidAttrName("_versioned", "usableFromInline", DAK_UsableFromInline, diag::attr_renamed_warning);
1563+
checkInvalidAttrName("_inlineable", "inlinable", DAK_Inlinable, diag::attr_renamed_warning);
15721564
} else {
1573-
checkRenamedAttr("_versioned", "usableFromInline", DAK_UsableFromInline, false);
1574-
checkRenamedAttr("_inlineable", "inlinable", DAK_Inlinable, false);
1565+
checkInvalidAttrName("_versioned", "usableFromInline", DAK_UsableFromInline, diag::attr_renamed);
1566+
checkInvalidAttrName("_inlineable", "inlinable", DAK_Inlinable, diag::attr_renamed);
15751567
}
15761568

15771569
if (DK == DAK_Count && Tok.getText() == "warn_unused_result") {

0 commit comments

Comments
 (0)