Skip to content

Commit 1bfd97d

Browse files
Moving expected_identifier_after_case_comma to comma location and improving tests
1 parent 8ea7fff commit 1bfd97d

File tree

2 files changed

+9
-9
lines changed

2 files changed

+9
-9
lines changed

lib/Parse/ParseDecl.cpp

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -5748,7 +5748,7 @@ Parser::parseDeclEnumCase(ParseDeclOptions Flags,
57485748

57495749
// Handle the likely case someone typed 'case X, case Y'.
57505750
if (Tok.is(tok::kw_case) && CommaLoc.isValid()) {
5751-
diagnose(Tok, diag::expected_identifier_after_case_comma);
5751+
diagnose(CommaLoc, diag::expected_identifier_after_case_comma);
57525752
Status.setIsParseError();
57535753
return Status;
57545754
}
@@ -5782,16 +5782,16 @@ Parser::parseDeclEnumCase(ParseDeclOptions Flags,
57825782
return Status;
57835783
}
57845784
}
5785-
if (CommaLoc.isValid() && !NameIsKeyword) {
5786-
diagnose(CommaLoc, diag::expected_identifier_after_case_comma);
5787-
Status.setIsParseError();
5788-
return Status;
5789-
} else if (NameIsKeyword) {
5785+
if (NameIsKeyword) {
57905786
diagnose(TokLoc, diag::keyword_cant_be_identifier, TokText);
57915787
diagnose(TokLoc, diag::backticks_to_escape)
57925788
.fixItReplace(TokLoc, "`" + TokText.str() + "`");
57935789
if (!Tok.isAtStartOfLine())
57945790
consumeToken();
5791+
} else if (CommaLoc.isValid()) {
5792+
diagnose(CommaLoc, diag::expected_identifier_after_case_comma);
5793+
Status.setIsParseError();
5794+
return Status;
57955795
} else {
57965796
diagnose(CaseLoc, diag::expected_identifier_in_decl, "enum 'case'");
57975797
}

test/Parse/enum.swift

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -101,8 +101,8 @@ enum ImproperlyHasIVars {
101101

102102
// We used to crash on this. rdar://14678675
103103
enum rdar14678675 {
104-
case U1,
105-
case U2 // expected-error{{expected identifier after comma in enum 'case' declaration}}
104+
case U1, // expected-error{{expected identifier after comma in enum 'case' declaration}}
105+
case U2
106106
case U3
107107
}
108108

@@ -578,4 +578,4 @@ enum SR11261_Newline2 {
578578

579579
enum SR11261_PatternMatching {
580580
case let .foo(x, y): // expected-error {{'case' label can only appear inside a 'switch' statement}}
581-
}
581+
}

0 commit comments

Comments
 (0)