Skip to content

[ANTLR] Import prefixed Function types are not described by the grammar. #54218

Closed
@modulovalue

Description

@modulovalue

Consider:

import 'dart:core' as other;

class Foo {
  other.Function foo() => throw 0;
}

Which results in the following parse trees:

 === Analyzer ===
Scan errors: 0
Parse errors: 0
<CompilationUnitImpl> [0-40]
┗━ <ClassDeclarationImpl> [0-39]
  ┣━ 'class' [0-5]
  ┣━ 'Foo' [6-9]
  ┣━ '{' [10-11]
  ┣━ <MethodDeclarationImpl> [14-37]
  ┃  ┣━ <NamedTypeImpl> [14-28]
  ┃  ┃  ┣━ <ImportPrefixReferenceImpl> [14-20]
  ┃  ┃  ┃  ┣━ 'other' [14-19]
  ┃  ┃  ┃  ┗━ '.' [19-20]
  ┃  ┃  ┗━ 'Function' [20-28]
  ┃  ┣━ 'foo' [29-32]
  ┃  ┣━ <FormalParameterListImpl> [32-34]
  ┃  ┃  ┣━ '(' [32-33]
  ┃  ┃  ┗━ ')' [33-34]
  ┃  ┗━ <BlockFunctionBodyImpl> [35-37]
  ┃    ┗━ <BlockImpl> [35-37]
  ┃      ┣━ '{' [35-36]
  ┃      ┗━ '}' [36-37]
  ┗━ '}' [38-39]
--------------------------------------------------------------------------------
 === ANTLR ===
Errors of type 1: [[@6,29:31='foo',<142>,2:17], [@6,29:31='foo',<142>,2:17]]
Errors of type 2: []
<startSymbol>
┗━ <libraryDefinition>
  ┣━ <metadata>
  ┣━ <topLevelDefinition>
  ┃  ┣━ <classModifiers>
  ┃  ┣━ 'class'
  ┃  ┣━ <typeWithParameters>
  ┃  ┃  ┗━ <typeIdentifier>
  ┃  ┃    ┗━ 'Foo'
  ┃  ┣━ '{'
  ┃  ┣━ <metadata>
  ┃  ┣━ <classMemberDeclaration>
  ┃  ┣━ <metadata>
  ┃  ┣━ <classMemberDeclaration>
  ┃  ┃  ┣━ 'other'
  ┃  ┃  ┗━ '.'
  ┃  ┣━ <metadata>
  ┃  ┣━ <classMemberDeclaration>
  ┃  ┃  ┣━ <methodSignature>
  ┃  ┃  ┃  ┗━ <functionSignature>
  ┃  ┃  ┃    ┣━ <type>
  ┃  ┃  ┃    ┃  ┗━ <typeNotFunction>
  ┃  ┃  ┃    ┃    ┗━ <typeNotVoidNotFunction>
  ┃  ┃  ┃    ┃      ┗━ 'Function'
  ┃  ┃  ┃    ┣━ <identifier>
  ┃  ┃  ┃    ┃  ┗━ 'foo'
  ┃  ┃  ┃    ┗━ <formalParameterPart>
  ┃  ┃  ┃      ┗━ <formalParameterList>
  ┃  ┃  ┃        ┣━ '('
  ┃  ┃  ┃        ┗━ ')'
  ┃  ┃  ┗━ <functionBody>
  ┃  ┃    ┗━ <block>
  ┃  ┃      ┣━ '{'
  ┃  ┃      ┣━ <statements>
  ┃  ┃      ┗━ '}'
  ┃  ┗━ '}'
  ┗━ '<EOF>'

The analyzer accepts that program without errors, but ANTLR does not.

It looks like the FUNCTION production of the typeNotVoidNotFunction production rule needs to accept an optional leading typeIdentifer '.':

sdk/tools/spec_parser/Dart.g

Lines 1442 to 1445 in 80ad968

typeNotVoidNotFunction
: typeName typeArguments?
| FUNCTION
;

Metadata

Metadata

Assignees

No one assigned

    Labels

    area-languageDart language related items (some items might be better tracked at github.com/dart-lang/language).language-spec-parser

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions