Skip to content

Commit 7c99877

Browse files
committed
Update the "'=' to ':' in attributes" fix-it to include a space.
...because it was bugging me, and because the migrator uses it.
1 parent 2db3e7e commit 7c99877

File tree

2 files changed

+11
-4
lines changed

2 files changed

+11
-4
lines changed

lib/Parse/ParseDecl.cpp

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -361,14 +361,15 @@ bool Parser::parseNewDeclAttribute(DeclAttributes &Attributes, SourceLoc AtLoc,
361361

362362

363363
// Check 'Tok', return false if ':' or '=' cannot be found.
364-
// Complain if '=' is found and suggest replacing it with ':'.
364+
// Complain if '=' is found and suggest replacing it with ": ".
365365
auto findAttrValueDelimiter = [&]() -> bool {
366366
if (!Tok.is(tok::colon)) {
367367
if (!Tok.is(tok::equal))
368368
return false;
369-
else
370-
diagnose(Tok.getLoc(), diag::replace_equal_with_colon_for_value)
371-
.fixItReplace(Tok.getLoc(), ":");
369+
370+
bool wantSpace = (Tok.getRange().getEnd() == peekToken().getLoc());
371+
diagnose(Tok.getLoc(), diag::replace_equal_with_colon_for_value)
372+
.fixItReplace(Tok.getLoc(), wantSpace ? ": " : ":");
372373
}
373374
return true;
374375
};

test/attr/attr_availability.swift

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -145,6 +145,12 @@ let _: Int
145145
@available(*, deprecated, unavailable, message: "message") // expected-error{{'available' attribute cannot be both unconditionally 'unavailable' and 'deprecated'}}
146146
struct BadUnconditionalAvailability { };
147147

148+
@available(*, unavailable, message="oh no you don't") // expected-error {{'=' has been replaced with ':' in attribute arguments}} {{35-36=: }}
149+
typealias EqualFixIt1 = Int
150+
@available(*, unavailable, message = "oh no you don't") // expected-error {{'=' has been replaced with ':' in attribute arguments}} {{36-37=:}}
151+
typealias EqualFixIt2 = Int
152+
153+
148154
// Encoding in messages
149155
@available(*, deprecated, message: "Say \"Hi\"")
150156
func deprecated_func_with_message() {}

0 commit comments

Comments
 (0)