Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[wildcard-variables] Clarify wildcard behaviour on functions. #3813

Merged
merged 1 commit into from
May 17, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 12 additions & 11 deletions working/wildcards/feature-specification.md
Original file line number Diff line number Diff line change
Expand Up @@ -76,21 +76,21 @@ library privacy comes into play.

## Proposal

### Local declarations
### Declarations that are capable of declaring a wildcard

A *local declaration* is any of:
Any of the following kinds of declarations can declare a wildcard:

* Function parameters. This includes top-level functions, local functions,
function expressions ("lambdas"), instance methods, static methods,
constructors, etc. It includes all parameter kinds: simple, field formals,
and function-typed formals, etc.:
constructors, etc. It includes all parameter kinds, excluding named
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I want to explicitly call this out. Not sure if this is the best place to write this. I know it's in Initializing formals, but it'd be nice to restate here.

parameters: simple, field formals, and function-typed formals, etc.:

```dart
Foo(_, this._, super._, void _(), {_}) {}
Foo(_, this._, super._, void _()) {}

list.where((_) => true);

void f(void g(_, _)) {}
void f(void g(int _, bool _)) {}

typedef T = void Function(String _, String _);
```
Expand Down Expand Up @@ -130,8 +130,8 @@ A *local declaration* is any of:
takeGenericCallback(<_>() => true);
```

A local declaration whose name is `_` does not bind that name to anything. This
means you can have multiple local declarations named `_` in the same namespace
A declaration whose name is `_` does not bind that name to anything. This
means you can have multiple declarations named `_` in the same namespace
without a collision error. The initializer, if there is one, is still executed,
but the value is not accessible.

Expand All @@ -153,12 +153,13 @@ Named fields of record types are unchanged. It is still a compile-time error for

```dart
void f() {
_() {} // Error.
_(); // Error.
_() {} // Dead code.
_(); // Error, not in scope.
}
```

It's an error to declare a local function declaration named `_`.
A local function declaration named `_` is dead code and will produce a warning
because the function is unreachable.

### Other declarations

Expand Down