sdk icon indicating copy to clipboard operation
sdk copied to clipboard

Bad recovery when a generic type alias missing name

Open scheglov opened this issue 1 year ago • 0 comments

It looks that we drop = completely, and so switch to a very synthetic legacy function type alias, although inserting a synthetic name could be a better recovery. Obviously, I don't know if it is feasible.

  test_modern_missingName() {
    var parseResult = parseStringWithErrors(r'''
typedef = int;
''');
    parseResult.assertErrors([
      error(ParserErrorCode.EXPECTED_TOKEN, 0, 7),
      error(ParserErrorCode.MISSING_IDENTIFIER, 8, 1),
      error(ParserErrorCode.MISSING_TYPEDEF_PARAMETERS, 8, 1),
      error(ParserErrorCode.EXPECTED_EXECUTABLE, 8, 1),
      error(ParserErrorCode.MISSING_CONST_FINAL_VAR_OR_TYPE, 10, 3),
    ]);

    var node = parseResult.findNode.unit;
    assertParsedNodeText(node, r'''
CompilationUnit
  declarations
    FunctionTypeAlias
      typedefKeyword: typedef
      name: <empty> <synthetic>
      parameters: FormalParameterList
        leftParenthesis: ( <synthetic>
        rightParenthesis: ) <synthetic>
      semicolon: ; <synthetic>
    TopLevelVariableDeclaration
      variables: VariableDeclarationList
        variables
          VariableDeclaration
            name: int
      semicolon: ;
''');
  }

scheglov avatar Oct 17 '24 19:10 scheglov