Clarify what was missing in binding pattern errors (#4314)

Co-authored-by: Josh L <josh11b@users.noreply.github.com>
This commit is contained in:
josh11b
2024-09-14 03:31:43 +00:00
committed by GitHub
co-authored by Josh L
parent c029931910
commit 7611aac355
16 changed files with 24 additions and 22 deletions
+7 -5
View File
@@ -25,11 +25,13 @@ auto HandleBindingPattern(Context& context) -> void {
}
// Handle an invalid pattern introducer for parameters and variables.
auto on_error = [&]() {
auto on_error = [&](llvm::StringLiteral expected) {
if (!state.has_error) {
CARBON_DIAGNOSTIC(ExpectedBindingPattern, Error,
"Expected binding pattern.");
context.emitter().Emit(*context.position(), ExpectedBindingPattern);
"Expected {0} in binding pattern.",
llvm::StringLiteral);
context.emitter().Emit(*context.position(), ExpectedBindingPattern,
expected);
state.has_error = true;
}
};
@@ -50,7 +52,7 @@ auto HandleBindingPattern(Context& context) -> void {
// Add a placeholder for the name.
context.AddLeafNode(NodeKind::IdentifierName, *context.position(),
/*has_error=*/true);
on_error();
on_error("name");
}
if (auto kind = context.PositionKind();
@@ -63,7 +65,7 @@ auto HandleBindingPattern(Context& context) -> void {
context.PushState(state);
context.PushStateForExpr(PrecedenceGroup::ForType());
} else {
on_error();
on_error("`:` or `:!`");
// Add a placeholder for the type.
context.AddLeafNode(NodeKind::InvalidParse, *context.position(),
/*has_error=*/true);