mirror of
https://github.com/carbon-language/carbon-lang.git
synced 2026-10-05 09:11:05 +01:00
Clarify what was missing in binding pattern errors (#4314)
Co-authored-by: Josh L <josh11b@users.noreply.github.com>
This commit is contained in:
@@ -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);
|
||||
|
||||
Reference in New Issue
Block a user