mirror of
https://github.com/carbon-language/carbon-lang.git
synced 2026-10-03 22:02:51 +01:00
Adjust how invalid declarations pass errors. (#2413)
When there's no semicolon for an invalid EmptyDeclaration, rather than producing nothing, produce an EmptyDeclaration with the original location that led to the error. Note this removes a direct edit (the only one) of the parse tree's error state. Elsewhere it's an indirection from adding an error node.
This commit is contained in:
@@ -705,11 +705,12 @@ auto Parser::HandleDeclarationLoopState() -> void {
|
||||
CARBON_DIAGNOSTIC(UnrecognizedDeclaration, Error,
|
||||
"Unrecognized declaration introducer.");
|
||||
emitter_->Emit(*position_, UnrecognizedDeclaration);
|
||||
tree_->has_errors_ = true;
|
||||
if (auto semi = SkipPastLikelyEnd(*position_)) {
|
||||
AddLeafNode(ParseNodeKind::EmptyDeclaration(), *semi,
|
||||
/*has_error=*/true);
|
||||
}
|
||||
auto cursor = *position_;
|
||||
auto semi = SkipPastLikelyEnd(cursor);
|
||||
// Locate the EmptyDeclaration at the semi when found, but use the
|
||||
// original cursor location for an error when not.
|
||||
AddLeafNode(ParseNodeKind::EmptyDeclaration(), semi ? *semi : cursor,
|
||||
/*has_error=*/true);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user