mirror of
https://github.com/carbon-language/carbon-lang.git
synced 2026-10-05 13:41:06 +01:00
Unify more invalid declaration recovery. (#3942)
When we expect a semicolon, we should be able to provide more standard
recovery.
Note this affects a test of `base`, but it looks like a partial
improvement (the prior line was moving too far). Still, it looks like
recovery isn't handling `{}` quite right. I'm not trying to address that
here though -- leaving a TODO.
This commit is contained in:
+15
-11
@@ -17,11 +17,15 @@ class A {
|
||||
// CHECK:STDERR:
|
||||
base: ;
|
||||
|
||||
// CHECK:STDERR: fail_base.carbon:[[@LINE+3]]:7: ERROR: Unrecognized declaration introducer.
|
||||
// CHECK:STDERR: base: { }
|
||||
// CHECK:STDERR: ^
|
||||
base: { }
|
||||
// We should resume parsing here after the previous error.
|
||||
// CHECK:STDERR: fail_base.carbon:[[@LINE+7]]:3: ERROR: `base` declarations must end with a `;`.
|
||||
// CHECK:STDERR: var n: i32;
|
||||
// CHECK:STDERR: ^~~
|
||||
// CHECK:STDERR:
|
||||
// CHECK:STDERR: fail_base.carbon:[[@LINE+3]]:7: ERROR: Unrecognized declaration introducer.
|
||||
// CHECK:STDERR: var n: i32;
|
||||
// CHECK:STDERR: ^
|
||||
var n: i32;
|
||||
}
|
||||
|
||||
@@ -37,14 +41,14 @@ class A {
|
||||
// CHECK:STDOUT: {kind: 'BaseIntroducer', text: 'base'},
|
||||
// CHECK:STDOUT: {kind: 'BaseColon', text: ':'},
|
||||
// CHECK:STDOUT: {kind: 'InvalidParse', text: ';', has_error: yes},
|
||||
// CHECK:STDOUT: {kind: 'BaseDecl', text: 'base', has_error: yes, subtree_size: 4},
|
||||
// CHECK:STDOUT: {kind: 'InvalidParseStart', text: ':', has_error: yes},
|
||||
// CHECK:STDOUT: {kind: 'InvalidParseSubtree', text: '}', has_error: yes, subtree_size: 2},
|
||||
// CHECK:STDOUT: {kind: 'VariableIntroducer', text: 'var'},
|
||||
// CHECK:STDOUT: {kind: 'IdentifierName', text: 'n'},
|
||||
// CHECK:STDOUT: {kind: 'IntTypeLiteral', text: 'i32'},
|
||||
// CHECK:STDOUT: {kind: 'BindingPattern', text: ':', subtree_size: 3},
|
||||
// CHECK:STDOUT: {kind: 'VariableDecl', text: ';', subtree_size: 5},
|
||||
// CHECK:STDOUT: {kind: 'BaseDecl', text: ';', has_error: yes, subtree_size: 4},
|
||||
// CHECK:STDOUT: {kind: 'BaseIntroducer', text: 'base'},
|
||||
// CHECK:STDOUT: {kind: 'BaseColon', text: ':'},
|
||||
// CHECK:STDOUT: {kind: 'StructLiteralStart', text: '{'},
|
||||
// CHECK:STDOUT: {kind: 'StructLiteral', text: '}', subtree_size: 2},
|
||||
// CHECK:STDOUT: {kind: 'BaseDecl', text: 'var', has_error: yes, subtree_size: 5},
|
||||
// CHECK:STDOUT: {kind: 'InvalidParseStart', text: 'n', has_error: yes},
|
||||
// CHECK:STDOUT: {kind: 'InvalidParseSubtree', text: ';', has_error: yes, subtree_size: 2},
|
||||
// CHECK:STDOUT: {kind: 'ClassDefinition', text: '}', subtree_size: 18},
|
||||
// CHECK:STDOUT: {kind: 'FileEnd', text: ''},
|
||||
// CHECK:STDOUT: ]
|
||||
|
||||
Reference in New Issue
Block a user