Skip to content

Commit 2b57b80

Browse files
committed
[Parser] Make parameter parsing still provide useful source locations when it fails.
1 parent b0470cf commit 2b57b80

File tree

1 file changed

+6
-11
lines changed

1 file changed

+6
-11
lines changed

lib/Parse/ParsePattern.cpp

Lines changed: 6 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -187,8 +187,7 @@ Parser::parseParameterClause(SourceLoc &leftParenLoc,
187187
if (!hasSpecifier) {
188188
if (Tok.is(tok::kw_let)) {
189189
diagnose(Tok, diag::parameter_let_as_attr)
190-
.fixItRemove(Tok.getLoc());
191-
param.isInvalid = true;
190+
.fixItRemove(Tok.getLoc());
192191
} else {
193192
// We handle the var error in sema for a better fixit and inout is
194193
// handled later in this function for better fixits.
@@ -201,9 +200,8 @@ Parser::parseParameterClause(SourceLoc &leftParenLoc,
201200
// Redundant specifiers are fairly common, recognize, reject, and recover
202201
// from this gracefully.
203202
diagnose(Tok, diag::parameter_inout_var_let_repeated)
204-
.fixItRemove(Tok.getLoc());
203+
.fixItRemove(Tok.getLoc());
205204
consumeToken();
206-
param.isInvalid = true;
207205
}
208206
}
209207

@@ -252,9 +250,8 @@ Parser::parseParameterClause(SourceLoc &leftParenLoc,
252250
hasValidInOut = true;
253251
if (hasSpecifier) {
254252
diagnose(Tok.getLoc(), diag::parameter_inout_var_let_repeated)
255-
.fixItRemove(param.LetVarInOutLoc);
253+
.fixItRemove(param.LetVarInOutLoc);
256254
consumeToken(tok::kw_inout);
257-
param.isInvalid = true;
258255
} else {
259256
hasSpecifier = true;
260257
param.LetVarInOutLoc = consumeToken(tok::kw_inout);
@@ -263,9 +260,8 @@ Parser::parseParameterClause(SourceLoc &leftParenLoc,
263260
}
264261
if (!hasValidInOut && hasDeprecatedInOut) {
265262
diagnose(Tok.getLoc(), diag::inout_as_attr_disallowed)
266-
.fixItRemove(param.LetVarInOutLoc)
267-
.fixItInsert(postColonLoc, "inout ");
268-
param.isInvalid = true;
263+
.fixItRemove(param.LetVarInOutLoc)
264+
.fixItInsert(postColonLoc, "inout ");
269265
}
270266

271267
auto type = parseType(diag::expected_parameter_type);
@@ -322,14 +318,13 @@ Parser::parseParameterClause(SourceLoc &leftParenLoc,
322318
if (param.Type) {
323319
diagnose(typeStartLoc, diag::parameter_unnamed)
324320
.fixItInsert(typeStartLoc, "_: ");
325-
} else {
326-
param.isInvalid = true;
327321
}
328322
} else {
329323
// Otherwise, we're not sure what is going on, but this doesn't smell
330324
// like a parameter.
331325
diagnose(Tok, diag::expected_parameter_name);
332326
param.isInvalid = true;
327+
param.FirstNameLoc = Tok.getLoc();
333328
}
334329
}
335330

0 commit comments

Comments
 (0)