Skip to content

Commit 6498c16

Browse files
committed
[Parser][SR-698][Qol] add diagnostic for trailing ',' in lists
https://bugs.swift.org/browse/SR-698
1 parent 55f8766 commit 6498c16

File tree

2 files changed

+11
-3
lines changed

2 files changed

+11
-3
lines changed

lib/Parse/Parser.cpp

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -659,11 +659,17 @@ Parser::parseList(tok RightK, SourceLoc LeftLoc, SourceLoc &RightLoc,
659659
RightLoc = Tok.getLoc();
660660
return Status;
661661
}
662+
SourceLoc SepLoc = Tok.getLoc();
662663
if (consumeIf(SeparatorK)) {
663-
if (AllowSepAfterLast && Tok.is(RightK))
664+
if (Tok.is(RightK)) {
665+
if (!AllowSepAfterLast) {
666+
diagnose(Tok, diag::unexpected_separator,
667+
SeparatorK == tok::comma ? "," : ";")
668+
.fixItRemove(SourceRange(SepLoc));
669+
}
664670
break;
665-
else
666-
continue;
671+
}
672+
continue;
667673
}
668674
if (!OptionalSep) {
669675
// If we're in a comma-separated list and the next token starts a new

test/Parse/invalid.swift

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -64,3 +64,5 @@ func f573(s Starfish, // expected-error {{parameter requires an explicit type}}
6464
_ ss: Salmon) -> [Int] {}
6565
func g573() { f573(Starfish(), Salmon()) }
6666

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

0 commit comments

Comments
 (0)