Skip to content

Catch clause with record type annotation #49995

Closed
@scheglov

Description

@scheglov

@jensjoha @munificent
This code:

void f() {
  try {
    f();
  } on int {
  } on (int, int) {
  }
}

is parsed as try/catch followed by a local function declaration.
Not as as two catch clauses with a record type annotation.
Might be an ambiguity in the grammar?

CompilationUnit
  declarations
    FunctionDeclaration
      returnType: NamedType
        name: SimpleIdentifier
          token: void
      name: f
      functionExpression: FunctionExpression
        parameters: FormalParameterList
          leftParenthesis: (
          rightParenthesis: )
        body: BlockFunctionBody
          block: Block
            leftBracket: {
            statements
              TryStatement
                tryKeyword: try
                body: Block
                  leftBracket: {
                  statements
                    ExpressionStatement
                      expression: MethodInvocation
                        methodName: SimpleIdentifier
                          token: f
                        argumentList: ArgumentList
                          leftParenthesis: (
                          rightParenthesis: )
                      semicolon: ;
                  rightBracket: }
                catchClauses
                  CatchClause
                    onKeyword: on
                    exceptionType: NamedType
                      name: SimpleIdentifier
                        token: int
                    body: Block
                      leftBracket: {
                      rightBracket: }
              FunctionDeclarationStatement
                functionDeclaration: FunctionDeclaration
                  name: on
                  functionExpression: FunctionExpression
                    parameters: FormalParameterList
                      leftParenthesis: (
                      parameter: SimpleFormalParameter
                        name: int
                      parameter: SimpleFormalParameter
                        name: int
                      rightParenthesis: )
                    body: BlockFunctionBody
                      block: Block
                        leftBracket: {
                        rightBracket: }
            rightBracket: }

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions