sdk icon indicating copy to clipboard operation
sdk copied to clipboard

Field formal parameter with explicit record type annotation parsed incorrectly

Open scheglov opened this issue 3 years ago • 0 comments

@jensjoha

We parse it as a function typed formal parameter instead.

class C {
  ({num n, String s}) r2;

  C(({int n, String s}) this.r2);
}

parsed as

[(41..41): Expected an identifier., (61..64): Expected to find ')'.]
class C {({num n, String s}) r2; C(({int n, String s}));}
CompilationUnit
  declarations
    ClassDeclaration
      classKeyword: class
      name: C
      leftBracket: {
      members
        FieldDeclaration
          fields: VariableDeclarationList
            type: RecordTypeAnnotation
              leftParenthesis: (
              namedFields: RecordTypeAnnotationNamedFields
                leftBracket: {
                fields
                  RecordTypeAnnotationNamedField
                    type: NamedType
                      name: SimpleIdentifier
                        token: num
                    name: n
                  RecordTypeAnnotationNamedField
                    type: NamedType
                      name: SimpleIdentifier
                        token: String
                    name: s
                rightBracket: }
              rightParenthesis: )
            variables
              VariableDeclaration
                name: r2
          semicolon: ;
        ConstructorDeclaration
          returnType: SimpleIdentifier
            token: C
          parameters: FormalParameterList
            leftParenthesis: (
            parameter: FunctionTypedFormalParameter
              name: <empty> <synthetic>
              parameters: FormalParameterList
                leftParenthesis: (
                leftDelimiter: {
                parameter: DefaultFormalParameter
                  parameter: SimpleFormalParameter
                    type: NamedType
                      name: SimpleIdentifier
                        token: int
                    name: n
                parameter: DefaultFormalParameter
                  parameter: SimpleFormalParameter
                    type: NamedType
                      name: SimpleIdentifier
                        token: String
                    name: s
                rightDelimiter: }
                rightParenthesis: )
            rightParenthesis: )
          body: EmptyFunctionBody
            semicolon: ;
      rightBracket: }

scheglov avatar Sep 19 '22 19:09 scheglov