Skip to content

Commit 482288a

Browse files
authored
[wildcard-variables] Clarify wildcard behaviour on functions. (#3813)
1 parent a38efbd commit 482288a

File tree

1 file changed

+12
-11
lines changed

1 file changed

+12
-11
lines changed

working/wildcards/feature-specification.md

Lines changed: 12 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -76,21 +76,21 @@ library privacy comes into play.
7676
7777
## Proposal
7878
79-
### Local declarations
79+
### Declarations that are capable of declaring a wildcard
8080
81-
A *local declaration* is any of:
81+
Any of the following kinds of declarations can declare a wildcard:
8282
8383
* Function parameters. This includes top-level functions, local functions,
8484
function expressions ("lambdas"), instance methods, static methods,
85-
constructors, etc. It includes all parameter kinds: simple, field formals,
86-
and function-typed formals, etc.:
85+
constructors, etc. It includes all parameter kinds, excluding named
86+
parameters: simple, field formals, and function-typed formals, etc.:
8787
8888
```dart
89-
Foo(_, this._, super._, void _(), {_}) {}
89+
Foo(_, this._, super._, void _()) {}
9090
9191
list.where((_) => true);
9292
93-
void f(void g(_, _)) {}
93+
void f(void g(int _, bool _)) {}
9494
9595
typedef T = void Function(String _, String _);
9696
```
@@ -130,8 +130,8 @@ A *local declaration* is any of:
130130
takeGenericCallback(<_>() => true);
131131
```
132132
133-
A local declaration whose name is `_` does not bind that name to anything. This
134-
means you can have multiple local declarations named `_` in the same namespace
133+
A declaration whose name is `_` does not bind that name to anything. This
134+
means you can have multiple declarations named `_` in the same namespace
135135
without a collision error. The initializer, if there is one, is still executed,
136136
but the value is not accessible.
137137
@@ -153,12 +153,13 @@ Named fields of record types are unchanged. It is still a compile-time error for
153153

154154
```dart
155155
void f() {
156-
_() {} // Error.
157-
_(); // Error.
156+
_() {} // Dead code.
157+
_(); // Error, not in scope.
158158
}
159159
```
160160

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

163164
### Other declarations
164165

0 commit comments

Comments
 (0)