Skip to content

Wildcards and primary constructor syntax #3720

@kallentu

Description

@kallentu

Trying to nail down the last few cases of wildcards. I'll regurgitate the issues and options that @munificent wrote to me and bring it up for discussion:

In the proposal, it states wildcards apply to local variables and parameters, but not to top-level variables and class members.

In an extension type, the primary constructor syntax looks like a parameter but defines a field. So if you have a parameter there named _, does it behave like a wildcard or like a field?

Likewise, when/if we add general primary constructor syntax, what does a parameter named _ mean?

Options:

  1. Yes, the wildcard proposal applies and it gets no name that you can use. Probably not very useful, but consistent with the syntax which does look like a parameter declaration.

  2. No, the wildcard proposal does not apply since you're defining a field. You get a field named _. Probably useful.

  3. Avoid the situation entirely by making it an error to have a parameter named _ in a primary constructor or extension type.

@dart-lang/language-team It would be good to make a decision on this and pick an outcome. Your input please?

Metadata

Metadata

Assignees

No one assigned

    Labels

    feature-completenessA special or edge case of another feature which isn't supported

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions