Skip to content

Commit b1ba769

Browse files
Minor changes for better clarity
1 parent 9b47fd6 commit b1ba769

File tree

4 files changed

+15
-13
lines changed

4 files changed

+15
-13
lines changed

lib/Parse/ParseDecl.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6798,12 +6798,12 @@ ParserStatus Parser::parseInheritance(
67986798

67996799
ParserStatus Status;
68006800
SourceLoc prevComma;
6801-
bool HasNextType;
6801+
bool HasComma;
68026802
bool IsEndOfList;
68036803
do {
68046804
SWIFT_DEFER {
68056805
// Check for a ',', which indicates that there are more protocols coming.
6806-
HasNextType = consumeIf(tok::comma, prevComma);
6806+
HasComma = consumeIf(tok::comma, prevComma);
68076807
IsEndOfList = (Context.LangOpts.hasFeature(Feature::TrailingComma) &&
68086808
(Tok.is(tok::l_brace) || Tok.is(tok::kw_where)));
68096809
};
@@ -6857,7 +6857,7 @@ ParserStatus Parser::parseInheritance(
68576857
// Record the type if its a single type.
68586858
if (ParsedTypeResult.isNonNull())
68596859
Inherited.push_back(InheritedEntry(ParsedTypeResult.get()));
6860-
} while (HasNextType && !IsEndOfList);
6860+
} while (HasComma && !IsEndOfList);
68616861

68626862
return Status;
68636863
}

lib/Parse/ParseExpr.cpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1926,6 +1926,8 @@ ParserResult<Expr> Parser::parseExprPrimary(Diag<> ID, bool isExprBasic) {
19261926
default:
19271927
UnknownCharacter:
19281928
checkForInputIncomplete();
1929+
// Enable trailing comma in string literal interpolation
1930+
// Note that 'Tok.is(tok::r_paren)' is not used because the text is ")\"\n" but the kind is actualy 'eof'
19291931
if (Tok.is(tok::eof) && Tok.getText() == ")") {
19301932
return nullptr;
19311933
}

lib/Parse/ParseGeneric.cpp

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ ParserStatus
4747
Parser::parseGenericParametersBeforeWhere(SourceLoc LAngleLoc,
4848
SmallVectorImpl<GenericTypeParamDecl *> &GenericParams) {
4949
ParserStatus Result;
50-
bool HasNextParam{};
50+
bool HasComma{};
5151
bool IsEndOfList;
5252
do {
5353
// Note that we're parsing a declaration.
@@ -133,9 +133,9 @@ Parser::parseGenericParametersBeforeWhere(SourceLoc LAngleLoc,
133133
Param->getAttrs() = attributes;
134134

135135
// Parse the comma, if the list continues.
136-
HasNextParam = consumeIf(tok::comma);
136+
HasComma = consumeIf(tok::comma);
137137
IsEndOfList = startsWithGreater(Tok);
138-
} while (HasNextParam && !IsEndOfList);
138+
} while (HasComma && !IsEndOfList);
139139

140140
return Result;
141141
}
@@ -278,7 +278,7 @@ ParserStatus Parser::parseGenericWhereClause(
278278
ParserStatus Status;
279279
// Parse the 'where'.
280280
WhereLoc = consumeToken(tok::kw_where);
281-
bool HasNextReq;
281+
bool HasComma;
282282
bool IsEndOfList;
283283
do {
284284
if (Tok.is(tok::code_complete)) {
@@ -404,18 +404,18 @@ ParserStatus Parser::parseGenericWhereClause(
404404
Status.setIsParseError();
405405
break;
406406
}
407-
HasNextReq = consumeIf(tok::comma);
407+
HasComma = consumeIf(tok::comma);
408408
IsEndOfList = (Context.LangOpts.hasFeature(Feature::TrailingComma) &&
409409
Tok.is(tok::l_brace));
410410
// If there's a comma, keep parsing the list.
411411
// If there's a "&&", diagnose replace with a comma and keep parsing
412-
if (Tok.isBinaryOperator() && Tok.getText() == "&&" && !HasNextReq) {
412+
if (Tok.isBinaryOperator() && Tok.getText() == "&&" && !HasComma) {
413413
diagnose(Tok, diag::requires_comma)
414414
.fixItReplace(SourceRange(Tok.getLoc()), ",");
415415
consumeToken();
416-
HasNextReq = true;
416+
HasComma = true;
417417
}
418-
} while (HasNextReq && !IsEndOfList);
418+
} while (HasComma && !IsEndOfList);
419419

420420
if (!Requirements.empty())
421421
EndLoc = Requirements.back().getSourceRange().End;

lib/Parse/ParseStmt.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1522,8 +1522,8 @@ Parser::parseAvailabilitySpecList(SmallVectorImpl<AvailabilitySpec *> &Specs,
15221522
consumeToken();
15231523
Status.setIsParseError();
15241524
} else if (consumeIf(tok::comma)) {
1525-
// End of list with a trailing comma.
1526-
if (Source != AvailabilitySpecSource::Available && Tok.is(tok::r_paren)) {
1525+
// End of unavailable spec list with a trailing comma.
1526+
if (Source == AvailabilitySpecSource::Unavailable && Tok.is(tok::r_paren)) {
15271527
break;
15281528
}
15291529
// There is more to parse in this list.

0 commit comments

Comments
 (0)