Skip to content

Commit 972fac5

Browse files
authored
Merge pull request #16667 from wickwirew/SR-7501-inlinable-misspelling
[SR-7501] inlinable misspelling
2 parents ff98bd4 + 303362c commit 972fac5

File tree

3 files changed

+21
-16
lines changed

3 files changed

+21
-16
lines changed

include/swift/AST/DiagnosticsParse.def

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1321,6 +1321,8 @@ ERROR(attr_renamed, none,
13211321
"'@%0' has been renamed to '@%1'", (StringRef, StringRef))
13221322
WARNING(attr_renamed_warning, none,
13231323
"'@%0' has been renamed to '@%1'", (StringRef, StringRef))
1324+
ERROR(attr_name_close_match, none,
1325+
"No attribute named '@%0', did you mean '@%1'?", (StringRef, StringRef))
13241326

13251327
// availability
13261328
ERROR(attr_availability_platform,none,

lib/Parse/ParseDecl.cpp

Lines changed: 15 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1536,35 +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);
1555+
1556+
// Check if attr is inlineable, and suggest inlinable instead
1557+
checkInvalidAttrName("inlineable", "inlinable", DAK_Inlinable, diag::attr_name_close_match);
15591558

15601559
// In Swift 5 and above, these become hard errors. Otherwise, emit a
15611560
// warning for compatibility.
15621561
if (!Context.isSwiftVersionAtLeast(5)) {
1563-
checkRenamedAttr("_versioned", "usableFromInline", DAK_UsableFromInline, true);
1564-
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);
15651564
} else {
1566-
checkRenamedAttr("_versioned", "usableFromInline", DAK_UsableFromInline, false);
1567-
checkRenamedAttr("_inlineable", "inlinable", DAK_Inlinable, false);
1565+
checkInvalidAttrName("_versioned", "usableFromInline", DAK_UsableFromInline, diag::attr_renamed);
1566+
checkInvalidAttrName("_inlineable", "inlinable", DAK_Inlinable, diag::attr_renamed);
15681567
}
15691568

15701569
if (DK == DAK_Count && Tok.getText() == "warn_unused_result") {
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
// RUN: %target-typecheck-verify-swift
2+
3+
@inlineable public func misspelledInlinable() {}
4+
// expected-error@-1 {{No attribute named '@inlineable', did you mean '@inlinable'?}}{{2-12=inlinable}}

0 commit comments

Comments
 (0)