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
The null-aware elements language feature enables a simple syntax for
18
+
including an element into a collection only if the element is not
19
+
null. The syntax is available for list elements, set elements, map
20
+
keys, and map values as described in the
21
+
[null-aware elements specification](https://github.com/dart-lang/language/blob/main/accepted/future-releases/0323-null-aware-elements/feature-specification.md).
22
+
23
+
The following is an example of a list literal written in both styles,
24
+
without the null-aware elements language feature and with it:
25
+
26
+
```dart
27
+
var listWithoutNullAwareElements = [
28
+
if (promotableNullableValue != null) promotableNullableValue,
29
+
if (nullable.value != null) nullable.value!,
30
+
if (nullable.value case var value?) value,
31
+
];
32
+
33
+
var listWithNullAwareElements = [
34
+
?promotableNullableValue,
35
+
?nullable.value,
36
+
?nullable.value,
37
+
];
38
+
```
39
+
7
40
### Libraries
8
41
9
42
#### `dart:core`
@@ -268,9 +301,10 @@ same as it was before.
268
301
269
302
### Language
270
303
271
-
Dart 3.7 adds [wildcard variables] to the language. To use them, set your
272
-
package's [SDK constraint][language version] lower bound to 3.7 or greater
273
-
(`sdk: '^3.7.0'`).
304
+
Dart 3.7 adds [wildcard variables] and [inference using
305
+
bounds][inference using bounds specification] to the language. To use
306
+
them, set your package's [SDK constraint][language version] lower
307
+
bound to 3.7 or greater (`sdk: '^3.7.0'`).
274
308
275
309
#### Wildcard Variables
276
310
@@ -297,6 +331,43 @@ main() {
297
331
}
298
332
```
299
333
334
+
#### Inference Using Bounds
335
+
336
+
[inference using bounds specification]: https://github.com/dart-lang/language/blob/main/accepted/future-releases/3009-inference-using-bounds/design-document.md
337
+
338
+
With the inference using bounds feature, Dart's type inference
339
+
algorithm generates constraints by combining existing constraints with
340
+
the declared type bounds, not just best-effort approximations.
341
+
342
+
This is especially important for F-bounded types, where inference
343
+
using bounds correctly infers that, in the example below, `X` can be
344
+
bound to `B`. Without the feature, the type argument must be specified
345
+
explicitly: `f<B>(C())`:
346
+
347
+
348
+
```dart
349
+
class A<X extends A<X>> {}
350
+
351
+
class B extends A<B> {}
352
+
353
+
class C extends B {}
354
+
355
+
void f<X extends A<X>>(X x) {}
356
+
357
+
void main() {
358
+
f(B()); // OK.
359
+
360
+
// OK with this feature. Without it, inference fails after detecting
361
+
// that C is not a subtype of A<C>.
362
+
f(C());
363
+
364
+
f<B>(C()); // OK.
365
+
}
366
+
```
367
+
368
+
The feature is described in more details in the
369
+
[inference using bounds specification][].
370
+
300
371
#### Other Language Changes
301
372
302
373
- **Breaking Change** [#56893][]: If a field is promoted to the type `Null`
0 commit comments