Skip to content

Do primary constructors carry metadata?Β #4496

@eernstg

Description

@eernstg

The current syntax in the proposal here does not allow for <metadata> in any location which is obviously concerned with the primary constructor. For example:

@metadata /* Not on the primary constructor. */
class C(final int x, final int y) extends B {}

// Noisy, not supported in the current grammar.
extension type @metadata const E._(List<X> xs) {}

// This is supported in the proposed grammar, and it's definitely on the primary constructor.
class D(super.x, super.y) extends C {
  @metadata
  this: assert(x != y);
}

@dart-lang/language-team, WDYT? Should we carve out a way to have metadata on a primary constructor, or are we just going to ask developers to use an in-body constructor or put it on the in-body part of the primary constructor? Presumably it can be quite minimal: @metadata this;.

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions