Skip to content

[Parser] Fix String interpolation accepts invalid argument label syntax without expression #80928

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 0 additions & 5 deletions lib/Parse/ParseExpr.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1924,11 +1924,6 @@ ParserResult<Expr> Parser::parseExprPrimary(Diag<> ID, bool isExprBasic) {
default:
UnknownCharacter:
checkForInputIncomplete();
// Enable trailing comma in string literal interpolation
// Note that 'Tok.is(tok::r_paren)' is not used because the text is ")\"\n" but the kind is actualy 'eof'
if (Tok.is(tok::eof) && Tok.getText() == ")") {
return nullptr;
}
// FIXME: offer a fixit: 'Self' -> 'self'
diagnose(Tok, ID);
return nullptr;
Expand Down
9 changes: 8 additions & 1 deletion lib/Parse/Parser.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1057,11 +1057,18 @@ Parser::parseListItem(ParserStatus &Status, tok RightK, SourceLoc LeftLoc,
return ParseListItemResult::Finished;
}
if (consumeIf(tok::comma)) {
if (Tok.isNot(RightK))
if (Tok.isNot(RightK) && !tokIsStringInterpolationEOF(Tok, RightK))
return ParseListItemResult::Continue;
if (!AllowSepAfterLast) {
diagnose(Tok, diag::unexpected_separator, ",").fixItRemove(PreviousLoc);
}

// Enable trailing comma in string literal interpolation
if (tokIsStringInterpolationEOF(Tok, RightK)) {
RightLoc = Tok.getLoc();
return ParseListItemResult::FinishedInStringInterpolation;
}

return ParseListItemResult::Finished;
}
// If we're in a comma-separated list, the next token is at the
Expand Down
1 change: 1 addition & 0 deletions test/Parse/trailing-comma.swift
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,7 @@ struct S {
// String Literal Interpolation

"\(1,)"
"\(1, f:)" // expected-error {{expected expression in list of expressions}}

// Availability Spec List

Expand Down