Skip to content

Add wildcard to method/constructor arguments [Breaking change suggestion] #2704

Closed
@julemand101

Description

@julemand101

(I could not find any issue similar to this. Also, I might be completely wrong and if that is the case, just close it :) )

As far as I understand the patterns proposal, we have a special meaning if a variable is called _ where we will not bind to any variable. But as far as I can read, it does not sound like this feature is going to be implemented in other areas like e.g. arguments to methods/constructors?

If not, then I would suggest the breaking change (maybe for Dart 3? Dart 4?) of making a _ in parameters an unbinding variable and make it so we cannot read this argument.

This should also make it possible to have multiple arguments named _ compare to the current behavior where _ is more like a suggestion from the programmer but data is still being assigned to the argument, which allow us to read the argument and prevents us from having multiple arguments named _ but are instead going to use __, ___ or similar.

As I see this, it would improve the usability of the language in general when patterns are introduced since I currently think it is kinda confusing that _ have a specific meaning in patterns but not outside of patterns.

I would expect a lot of people are already using _ to communicate an argument is not going to be used. But I do wonder how many are actually reading from an argument named _.

Metadata

Metadata

Assignees

No one assigned

    Labels

    featureProposed language feature that solves one or more problemspatternsIssues related to pattern matching.

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions