Skip to content

Commit b573667

Browse files
chloestefantsovaCommit Queue
authored andcommitted
Update CHANGELOG.md with entries about null-aware elements and inference using bounds
Change-Id: I47a2d17e8d15028c13fa0319069152323e4920ef Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/424444 Reviewed-by: Erik Ernst <[email protected]> Reviewed-by: Michael Thomsen <[email protected]> Commit-Queue: Chloe Stefantsova <[email protected]>
1 parent 1a17e9e commit b573667

File tree

1 file changed

+74
-3
lines changed

1 file changed

+74
-3
lines changed

CHANGELOG.md

Lines changed: 74 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,39 @@
44

55
**Released on:** Unreleased
66

7+
### Language
8+
9+
Dart 3.8 adds [null-aware elements] to the language. To use them, set
10+
your package's [SDK constraint][language version] lower bound to 3.8
11+
or greater (`sdk: '^3.8.0'`).
12+
13+
#### Null-Aware Elements
14+
15+
[null-aware elements]: https://github.com/dart-lang/language/issues/323
16+
17+
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+
740
### Libraries
841

942
#### `dart:core`
@@ -268,9 +301,10 @@ same as it was before.
268301

269302
### Language
270303

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'`).
274308
275309
#### Wildcard Variables
276310
@@ -297,6 +331,43 @@ main() {
297331
}
298332
```
299333

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+
300371
#### Other Language Changes
301372

302373
- **Breaking Change** [#56893][]: If a field is promoted to the type `Null`

0 commit comments

Comments
 (0)