Skip to content

[4.2] [SR-7501] inlinable misspelling #16708

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions include/swift/AST/DiagnosticsParse.def
Original file line number Diff line number Diff line change
Expand Up @@ -1320,6 +1320,8 @@ ERROR(attr_renamed, none,
"'@%0' has been renamed to '@%1'", (StringRef, StringRef))
WARNING(attr_renamed_warning, none,
"'@%0' has been renamed to '@%1'", (StringRef, StringRef))
ERROR(attr_name_close_match, none,
"no attribute named '@%0'; did you mean '@%1'?", (StringRef, StringRef))

// availability
ERROR(attr_availability_platform,none,
Expand Down
31 changes: 15 additions & 16 deletions lib/Parse/ParseDecl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1465,35 +1465,34 @@ bool Parser::parseDeclAttribute(DeclAttributes &Attributes, SourceLoc AtLoc) {
// If the attribute follows the new representation, switch
// over to the alternate parsing path.
DeclAttrKind DK = DeclAttribute::getAttrKindFromString(Tok.getText());

auto checkRenamedAttr = [&](StringRef oldName, StringRef newName,
DeclAttrKind kind, bool warning) {
if (DK == DAK_Count && Tok.getText() == oldName) {
auto checkInvalidAttrName = [&](StringRef invalidName, StringRef correctName,
DeclAttrKind kind, Diag<StringRef, StringRef> diag) {
if (DK == DAK_Count && Tok.getText() == invalidName) {
// We renamed @availability to @available, so if we see the former,
// treat it as the latter and emit a Fix-It.
DK = kind;
if (warning) {
diagnose(Tok, diag::attr_renamed_warning, oldName, newName)
.fixItReplace(Tok.getLoc(), newName);
} else {
diagnose(Tok, diag::attr_renamed, oldName, newName)
.fixItReplace(Tok.getLoc(), newName);
}

diagnose(Tok, diag, invalidName, correctName)
.fixItReplace(Tok.getLoc(), correctName);
}
};

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

// Check if attr is inlineable, and suggest inlinable instead
checkInvalidAttrName("inlineable", "inlinable", DAK_Inlinable, diag::attr_name_close_match);

// In Swift 5 and above, these become hard errors. Otherwise, emit a
// warning for compatibility.
if (!Context.isSwiftVersionAtLeast(5)) {
checkRenamedAttr("_versioned", "usableFromInline", DAK_UsableFromInline, true);
checkRenamedAttr("_inlineable", "inlinable", DAK_Inlinable, true);
checkInvalidAttrName("_versioned", "usableFromInline", DAK_UsableFromInline, diag::attr_renamed_warning);
checkInvalidAttrName("_inlineable", "inlinable", DAK_Inlinable, diag::attr_renamed_warning);
} else {
checkRenamedAttr("_versioned", "usableFromInline", DAK_UsableFromInline, false);
checkRenamedAttr("_inlineable", "inlinable", DAK_Inlinable, false);
checkInvalidAttrName("_versioned", "usableFromInline", DAK_UsableFromInline, diag::attr_renamed);
checkInvalidAttrName("_inlineable", "inlinable", DAK_Inlinable, diag::attr_renamed);
}

if (DK == DAK_Count && Tok.getText() == "warn_unused_result") {
Expand Down
4 changes: 4 additions & 0 deletions test/attr/attr_inlinable_close_match.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
// RUN: %target-typecheck-verify-swift

@inlineable public func misspelledInlinable() {}
// expected-error@-1 {{no attribute named '@inlineable'; did you mean '@inlinable'?}}{{2-12=inlinable}}