You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
[wildcard-variables] Add more explicit details on functions and records. (#3802)
* [wildcard-variables] Add more explicit details on functions and records.
* Rewrite record type positional fields and add newline.
* Named fields of record types are unchanged.
Copy file name to clipboardExpand all lines: working/wildcards/feature-specification.md
+43-3Lines changed: 43 additions & 3 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -4,7 +4,9 @@ Author: Bob Nystrom
4
4
5
5
Status: In-progress
6
6
7
-
Version 1.2
7
+
Version 1.3
8
+
9
+
## Motivation
8
10
9
11
Pattern matching brings a new way to declare variables. Inside patterns, any
10
12
variable whose name is `_` is considered a "wildcard". It behaves like a
@@ -74,6 +76,8 @@ library privacy comes into play.
74
76
75
77
## Proposal
76
78
79
+
### Local declarations
80
+
77
81
A *local declaration* is any of:
78
82
79
83
* Function parameters. This includes top-level functions, local functions,
@@ -85,6 +89,10 @@ A *local declaration* is any of:
85
89
Foo(_, this._, super._, void _(), {_}) {}
86
90
87
91
list.where((_) => true);
92
+
93
+
void f(void g(_, _)) {}
94
+
95
+
typedef T = void Function(String _, String _);
88
96
```
89
97
90
98
* Local variable declaration statement variables.
@@ -127,8 +135,35 @@ means you can have multiple local declarations named `_` in the same namespace
127
135
without a collision error. The initializer, if there is one, is still executed,
128
136
but the value is not accessible.
129
137
130
-
Other declarations: top-level variables, top-level function names, type names,
131
-
member names, etc. are unchanged. They can be named `_` as they are today.
138
+
### Record type positional fields
139
+
140
+
```dart
141
+
typedef R = (String _, String _);
142
+
(int _, int _) record;
143
+
```
144
+
145
+
It is currently an error for a record field name to begin with `_`
146
+
(including just a bare `_`). We relax that error to only apply to record
147
+
fields whose name begins with `_` followed by at least one other character
148
+
(even if those later character(s) are `_`).
149
+
150
+
Named fields of record types are unchanged. It is still a compile-time error for a named field name to start with `_`.
151
+
152
+
### Local function declarations
153
+
154
+
```dart
155
+
void f() {
156
+
_() {} // Error.
157
+
_(); // Error.
158
+
}
159
+
```
160
+
161
+
It's an error to declare a local function declaration named `_`.
162
+
163
+
### Other declarations
164
+
165
+
Top-level variables, top-level function names, type names, member names,
166
+
etc. are unchanged. They can be named `_` as they are today.
132
167
133
168
We do not change how identifier *expressions* behave. Members can be named `_`
134
169
and you can access them from inside the class where the member is declared
@@ -403,6 +438,11 @@ This lint is included in the core lint set which means that the scale of the bre
403
438
404
439
## Changelog
405
440
441
+
### 1.3
442
+
443
+
- Add section on local function declarations. Discussion: [language/#3790](https://github.com/dart-lang/language/issues/3790)
444
+
- Add section on record type positionals and more examples with function types. Discussion: [language/#3791](https://github.com/dart-lang/language/issues/3791)
445
+
406
446
### 1.2
407
447
408
448
- Add information about the [`no_wildcard_variable_uses`](https://dart.dev/tools/linter-rules/no_wildcard_variable_uses) lint.
0 commit comments