Skip to content

Language grammar treats metadata inconsistently in several kinds of declarations #28283

@eernstg

Description

@eernstg

The language grammar (referring to the current version of dartLangSpec.tex, from commit c63f801) specifies for certain declarations that a built-in identifier should be placed before the metadata of that declaration, or the metadata is missing entirely. Consider for example top level definitions:

topLevelDefinition:
     ...
     'external'? functionSignature ';' |
     'external'? getterSignature ';' |
     'external'? setterSignature ';'

With the first alternative we can derive this:

external @foo void f();

With getterSignature and setterSignature there is no metadata at all. This seems to be inconsistent (the metadata typically comes first, and metadata is allowed on most kinds of declarations), and @bwilkerson noted that the tools currently do not follow the grammar in the language specification: they require the metadata to come first, and they do allow getters and setters to have metadata at the top level.

There is a somewhat similar issue with class members:

classDefinition:
     metadata 'abstract'? 'class' identifier typeParameters?
     (superclass mixins?)? interfaces?
     '{' (metadata classMemberDefinition)* '}'
classMemberDefinition:
     declaration ';' |
     methodSignature functionBody
methodSignature:
     ... |
     'static'? functionSignature |
     ...
declaration:
     ... |
     ('external' 'static'?)? functionSignature |
     ...

Here we can derive a class member like @foo static @bar void f() {} and @foo external static @bar void f();, where @bar looks spurious.

We may be able to simply remove metadata from functionSignature and then add metadata to several other parts of the grammar, but it would be useful to correlate the grammar corrections with the actual implementations such that the spec and the implementations differ as little as possible.

Metadata

Metadata

Assignees

No one assigned

    Labels

    area-specification (deprecated)Deprecated: use area-language and a language- label.type-bugIncorrect behavior (everything from a crash to more subtle misbehavior)

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions