Skip to content

Primary constructors spec question #4586

@bwilkerson

Description

@bwilkerson

In the specification of primary constructors there is text that reads:

The grammar is ambiguous with regard to the keyword factory. For example, factory() => C(); could be a method named factory with an implicitly inferred return type, or it could be a factory constructor whose name is the name of the enclosing class.

This ambiguity is resolved as follows: When a Dart parser expects to parse a <memberDeclaration>, and the beginning of the declaration is factory or one or more of the modifiers const, augment, or external followed by factory, it proceeds to parse the following input as a factory constructor.

It's my understanding that an instance method can't start with const, so I believe that the presence of a const modifier would already force the construct to be interpreted as a constructor (once the parser determines that it isn't a field). If that's true, then it would be better to remove the unnecessary const from the list to avoid confusion.

I don't know whether the augmentations feature is going to allow both augment and external to be applied to the same constructor declaration, but if const is removed from the list then the "or more" might not be needed.

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugThere is a mistake in the language specification or in an active documentprimary-constructorsFeature for less verbose constructors, otherwise known as declaring constructors.

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions