Skip to content

Named _p is augmented by p? #4710

Description

@eernstg

The augmentations feature specification states that an augmenting declaration matches the augmented one only when (among other things):

  • It has the same set of named parameter names as the introductory declaration.

It is an error for an augmenting declaration to fail to match the introductory declaration.

The private named parameters feature specification states that a named formal parameter whose name is private is a compile-time error unless the parameter is initializing (e.g., this._p) or declaring (e.g., final int _p or var _p):

If a user tries to put _ before a named parameter that isn't an initializing formal or declaring parameter, it's an error.

At the same time, it is an error for more than one declaration in an augmentation chain declaring a constructor to be complete, and an initializing as well as a declaring formal parameter makes the declaration complete, no matter what else it contains.

So, apparently, we can't augment an initializing or declaring named formal parameter if its name is private, and similarly for initializing formals. For example:

class C({final int _p}); // OK.

augment class C {
  // One attempt.
  new({@metaSomething int _p}); // Error, bad parameter name.
  // Another attempt.
  new({@metaSomething int p}); // Error, the parameter name does not match.
}

The "another attempt" approach seems to be somewhat in line with the treatment of super parameters, but apparently we will need to change a few words in a specification document in order to allow it.

@dart-lang/language-team, WDYT?

Metadata

Metadata

Assignees

No one assigned

    Labels

    augmentationsIssues related to the augmentations proposal.primary-constructorsFeature for less verbose constructors, otherwise known as declaring constructors.questionFurther information is requested

    Type

    No type

    Fields

    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions