Skip to content

Commit

Permalink
Add fix-it to change @Availability to @available.
Browse files Browse the repository at this point in the history
When we parse '@Availability', treat it as '@available' and emit a Fix-It to rename.

rdar://problem/20974602

Swift SVN r28771
  • Loading branch information
devincoughlin committed May 19, 2015
1 parent 4e4a73f commit bf402b3
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 0 deletions.
3 changes: 3 additions & 0 deletions include/swift/AST/DiagnosticsParse.def
Original file line number Diff line number Diff line change
Expand Up @@ -1076,6 +1076,9 @@ ERROR(attr_availability_expected_equal,attribute_parsing,none,
ERROR(attr_availability_expected_version,attribute_parsing,none,
"expected version number in '%0' attribute", (StringRef))

ERROR(attr_availability_renamed, attribute_parsing, none,
"@availability has been renamed to @available", ())

// autoclosure
ERROR(attr_autoclosure_expected_r_paren,attribute_parsing,PointsToFirstBadToken,
"expected ')' in @autoclosure", ())
Expand Down
9 changes: 9 additions & 0 deletions lib/Parse/ParseDecl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1247,6 +1247,15 @@ 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());

if (DK == DAK_Count && Tok.getText() == "availability") {
// We renamed @availability to @available, so if we see the former,
// treat it as the latter and emit a Fix-It.
DK = DAK_Available;
diagnose(Tok, diag::attr_availability_renamed)
.fixItReplace(Tok.getLoc(), "available");
}

if (DK != DAK_Count && !DeclAttribute::shouldBeRejectedByParser(DK))
return parseNewDeclAttribute(Attributes, AtLoc, DK);

Expand Down
3 changes: 3 additions & 0 deletions test/attr/attr_availability.swift
Original file line number Diff line number Diff line change
Expand Up @@ -182,3 +182,6 @@ func shortFormWithWildcardInMiddle() {}

@available(iOS 8.0, OSX 10.10.3) // expected-error {{must handle potential future platforms with '*'}}
func shortFormMissingWildcard() {}

@availability(OSX, introduced=10.10) // expected-error {{@availability has been renamed to @available}} {{2-14=available}}
func someFuncUsingOldAttribute() { }

0 comments on commit bf402b3

Please sign in to comment.