Skip to content

Commit 533ae2b

Browse files
authored
Merge pull request #80928 from kntkymt/kntk-trailing-comma-string-interpolation
[Parser] Fix String interpolation accepts invalid argument label syntax without expression
2 parents d788713 + 77decfd commit 533ae2b

File tree

3 files changed

+9
-6
lines changed

3 files changed

+9
-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

test/Parse/trailing-comma.swift

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,7 @@ struct S {
6060
// String Literal Interpolation
6161

6262
"\(1,)"
63+
"\(1, f:)" // expected-error {{expected expression in list of expressions}}
6364
6465
// Availability Spec List
6566

0 commit comments

Comments
 (0)