Skip to content

[Parser][SR-698][Qol] add diagnostic for trailing ',' in lists #1265

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 1 commit into from
Feb 11, 2016
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
12 changes: 9 additions & 3 deletions lib/Parse/Parser.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -659,11 +659,17 @@ Parser::parseList(tok RightK, SourceLoc LeftLoc, SourceLoc &RightLoc,
RightLoc = Tok.getLoc();
return Status;
}
SourceLoc SepLoc = Tok.getLoc();
if (consumeIf(SeparatorK)) {
if (AllowSepAfterLast && Tok.is(RightK))
if (Tok.is(RightK)) {
if (!AllowSepAfterLast) {
diagnose(Tok, diag::unexpected_separator,
SeparatorK == tok::comma ? "," : ";")
.fixItRemove(SourceRange(SepLoc));
}
break;
else
continue;
}
continue;
}
if (!OptionalSep) {
// If we're in a comma-separated list and the next token starts a new
Expand Down
2 changes: 2 additions & 0 deletions test/Parse/invalid.swift
Original file line number Diff line number Diff line change
Expand Up @@ -64,3 +64,5 @@ func f573(s Starfish, // expected-error {{parameter requires an explicit type}}
_ ss: Salmon) -> [Int] {}
func g573() { f573(Starfish(), Salmon()) }

func SR698(a: Int, b: Int) {}
SR698(1, b: 2,) // expected-error {{unexpected ',' separator}}