Skip to content

Commit 80baae1

Browse files
committed
[Parser] fix parse trailing commna in string interpolation at the end of parseListItem flow instead
1 parent 7d77c61 commit 80baae1

File tree

2 files changed

+8
-6
lines changed

2 files changed

+8
-6
lines changed

lib/Parse/ParseExpr.cpp

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1908,11 +1908,6 @@ ParserResult<Expr> Parser::parseExprPrimary(Diag<> ID, bool isExprBasic) {
19081908
default:
19091909
UnknownCharacter:
19101910
checkForInputIncomplete();
1911-
// Enable trailing comma in string literal interpolation
1912-
// Note that 'Tok.is(tok::r_paren)' is not used because the text is ")\"\n" but the kind is actualy 'eof'
1913-
if (Tok.is(tok::eof) && Tok.getText() == ")") {
1914-
return nullptr;
1915-
}
19161911
// FIXME: offer a fixit: 'Self' -> 'self'
19171912
diagnose(Tok, ID);
19181913
return nullptr;

lib/Parse/Parser.cpp

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1057,11 +1057,18 @@ Parser::parseListItem(ParserStatus &Status, tok RightK, SourceLoc LeftLoc,
10571057
return ParseListItemResult::Finished;
10581058
}
10591059
if (consumeIf(tok::comma)) {
1060-
if (Tok.isNot(RightK))
1060+
if (Tok.isNot(RightK) && !tokIsStringInterpolationEOF(Tok, RightK))
10611061
return ParseListItemResult::Continue;
10621062
if (!AllowSepAfterLast) {
10631063
diagnose(Tok, diag::unexpected_separator, ",").fixItRemove(PreviousLoc);
10641064
}
1065+
1066+
// Enable trailing comma in string literal interpolation
1067+
if (tokIsStringInterpolationEOF(Tok, RightK)) {
1068+
RightLoc = Tok.getLoc();
1069+
return ParseListItemResult::FinishedInStringInterpolation;
1070+
}
1071+
10651072
return ParseListItemResult::Finished;
10661073
}
10671074
// If we're in a comma-separated list, the next token is at the

0 commit comments

Comments
 (0)