mirror of
https://github.com/carbon-language/carbon-lang.git
synced 2026-10-05 21:31:24 +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;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -5,6 +5,7 @@
|
||||
// AUTOUPDATE
|
||||
// RUN: %{not} %{carbon-run-parser}
|
||||
// CHECK:STDOUT: [
|
||||
// CHECK:STDOUT: {kind: 'EmptyDeclaration', text: 'foo', has_error: yes},
|
||||
// CHECK:STDOUT: {kind: 'FileEnd', text: ''},
|
||||
// CHECK:STDOUT: ]
|
||||
|
||||
|
||||
+1
@@ -5,6 +5,7 @@
|
||||
// AUTOUPDATE
|
||||
// RUN: %{not} %{carbon-run-parser}
|
||||
// CHECK:STDOUT: [
|
||||
// CHECK:STDOUT: {kind: 'EmptyDeclaration', text: 'struct', has_error: yes},
|
||||
// CHECK:STDOUT: {kind: 'FunctionIntroducer', text: 'fn'},
|
||||
// CHECK:STDOUT: {kind: 'DeclaredName', text: 'F'},
|
||||
// CHECK:STDOUT: {kind: 'ParameterListStart', text: '('},
|
||||
|
||||
Reference in New Issue
Block a user