Skip to content

Improve parser recovery for trailing name in field declaration #60947

Open
@scheglov

Description

@scheglov

Code like int foo,; is currently parsed as having two variable declarations, which causes also FieldFragment with null name. But there is very little from the variable declaration, just a comma. And a better recovery would probably be just report that there is a not supported trailing comma, and don't create a new empty variable declaration.

  test_XXX() {
    var parseResult = parseStringWithErrors(r'''
class A {
  int foo,;
}
''');

    var node = parseResult.findNode.singleFieldDeclaration;
    assertParsedNodeText(node, r'''
FieldDeclaration
  fields: VariableDeclarationList
    type: NamedType
      name: int
    variables
      VariableDeclaration
        name: foo
      VariableDeclaration
        name: <empty> <synthetic>
  semicolon: ;
''');
  }

Metadata

Metadata

Assignees

No one assigned

    Labels

    area-dart-modelFor issues related to conformance to the language spec in the parser, compilers or the CLI analyzer.model-error-recoveryError recovery in analyzer/CFE.model-parserParser issues in the analyzer/CFE

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions