Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Closed
modulovalue opened this issue Dec 3, 2023 · 2 comments
Closed
Labels
area-language Dart language related items (some items might be better tracked at github.com/dart-lang/language). language-spec-parser

Comments

@modulovalue
Copy link
Contributor

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
;

@eernstg
Copy link
Member

eernstg commented Dec 4, 2023

Good catch, thanks! See dart-lang/language#3492 and https://dart-review.googlesource.com/339561.

@lrhn lrhn added area-language Dart language related items (some items might be better tracked at github.com/dart-lang/language). language-spec-parser labels Dec 5, 2023
@modulovalue
Copy link
Contributor Author

This appears to have been fixed.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area-language Dart language related items (some items might be better tracked at github.com/dart-lang/language). language-spec-parser
Projects
None yet
Development

No branches or pull requests

3 participants