Skip to content

Commit 140cbaa

Browse files
committed
[Parser] Allow $ prefixes on argument labels and closure parameter
declarations.
1 parent 1486352 commit 140cbaa

File tree

4 files changed

+14
-9
lines changed

4 files changed

+14
-9
lines changed

Diff for: include/swift/Parse/Parser.h

+3-2
Original file line numberDiff line numberDiff line change
@@ -563,15 +563,16 @@ class Parser {
563563
return consumeToken();
564564
}
565565

566-
SourceLoc consumeArgumentLabel(Identifier &Result) {
566+
SourceLoc consumeArgumentLabel(Identifier &Result,
567+
bool diagnoseDollarPrefix) {
567568
assert(Tok.canBeArgumentLabel());
568569
assert(Result.empty());
569570
if (!Tok.is(tok::kw__)) {
570571
Tok.setKind(tok::identifier);
571572
Result = Context.getIdentifier(Tok.getText());
572573

573574
if (Tok.getText()[0] == '$')
574-
diagnoseDollarIdentifier(Tok, /*diagnoseDollarPrefix=*/true);
575+
diagnoseDollarIdentifier(Tok, diagnoseDollarPrefix);
575576
}
576577
return consumeToken();
577578
}

Diff for: lib/Parse/ParseExpr.cpp

+3-3
Original file line numberDiff line numberDiff line change
@@ -2048,7 +2048,7 @@ void Parser::parseOptionalArgumentLabel(Identifier &name, SourceLoc &loc) {
20482048
.fixItRemoveChars(end.getAdvancedLoc(-1), end);
20492049
}
20502050

2051-
loc = consumeArgumentLabel(name);
2051+
loc = consumeArgumentLabel(name, /*diagnoseDollarPrefix=*/false);
20522052
consumeToken(tok::colon);
20532053
}
20542054
}
@@ -2599,7 +2599,7 @@ ParserStatus Parser::parseClosureSignatureIfPresent(
25992599
Identifier name;
26002600
SourceLoc nameLoc;
26012601
if (Tok.is(tok::identifier)) {
2602-
nameLoc = consumeIdentifier(name, /*diagnoseDollarPrefix=*/true);
2602+
nameLoc = consumeIdentifier(name, /*diagnoseDollarPrefix=*/false);
26032603
} else {
26042604
nameLoc = consumeToken(tok::kw__);
26052605
}
@@ -3175,7 +3175,7 @@ Parser::parseTrailingClosures(bool isExprBasic, SourceRange calleeRange,
31753175
SyntaxParsingContext ClosureCtx(SyntaxContext,
31763176
SyntaxKind::MultipleTrailingClosureElement);
31773177
Identifier label;
3178-
auto labelLoc = consumeArgumentLabel(label);
3178+
auto labelLoc = consumeArgumentLabel(label, /*diagnoseDollarPrefix=*/false);
31793179
consumeToken(tok::colon);
31803180
ParserResult<Expr> closure;
31813181
if (Tok.is(tok::l_brace)) {

Diff for: lib/Parse/ParsePattern.cpp

+4-2
Original file line numberDiff line numberDiff line change
@@ -276,11 +276,13 @@ Parser::parseParameterClause(SourceLoc &leftParenLoc,
276276

277277
if (startsParameterName(*this, isClosure)) {
278278
// identifier-or-none for the first name
279-
param.FirstNameLoc = consumeArgumentLabel(param.FirstName);
279+
param.FirstNameLoc = consumeArgumentLabel(param.FirstName,
280+
/*diagnoseDollarPrefix=*/!isClosure);
280281

281282
// identifier-or-none? for the second name
282283
if (Tok.canBeArgumentLabel())
283-
param.SecondNameLoc = consumeArgumentLabel(param.SecondName);
284+
param.SecondNameLoc = consumeArgumentLabel(param.SecondName,
285+
/*diagnoseDollarPrefix=*/true);
284286

285287
// Operators, closures, and enum elements cannot have API names.
286288
if ((paramContext == ParameterContextKind::Operator ||

Diff for: lib/Parse/ParseType.cpp

+4-2
Original file line numberDiff line numberDiff line change
@@ -1020,11 +1020,13 @@ ParserResult<TypeRepr> Parser::parseTypeTupleBody() {
10201020
&& (peekToken().is(tok::colon)
10211021
|| peekToken().canBeArgumentLabel())) {
10221022
// Consume a name.
1023-
element.NameLoc = consumeArgumentLabel(element.Name);
1023+
element.NameLoc = consumeArgumentLabel(element.Name,
1024+
/*diagnoseDollarPrefix=*/true);
10241025

10251026
// If there is a second name, consume it as well.
10261027
if (Tok.canBeArgumentLabel())
1027-
element.SecondNameLoc = consumeArgumentLabel(element.SecondName);
1028+
element.SecondNameLoc = consumeArgumentLabel(element.SecondName,
1029+
/*diagnoseDollarPrefix=*/true);
10281030

10291031
// Consume the ':'.
10301032
if (consumeIf(tok::colon, element.ColonLoc)) {

0 commit comments

Comments
 (0)