Add changelog for static extension members.

Change-Id: I85bb821ce8b4331540b67e0288c6b029bf0ec0df
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/119842
Commit-Queue: Lasse R.H. Nielsen <lrn@google.com>
Reviewed-by: Leaf Petersen <leafp@google.com>
Reviewed-by: Alexander Thomas <athom@google.com>
Auto-Submit: Lasse R.H. Nielsen <lrn@google.com>
This commit is contained in:
Lasse R.H. Nielsen 2019-10-04 08:27:54 +00:00 committed by commit-bot@chromium.org
parent 5a6d17d362
commit ad78373d6c

View file

@ -4,6 +4,58 @@
### Language ### Language
* [Static extension members][]: A new language feature allowing
specially declared static functions to be invoked
like instance members on expressions of appropriate static types.
Static extension members are declared using a new `extension`
declaration. Example:
```dart
extension MyFancyList<T> on List<T> {
/// Whether this list has an even length.
bool get isLengthEven => this.length.isEven;
/// Whether this list has an odd length.
bool get isLengthOdd => !isLengthEven;
/// List of values computed for each pairs of adjacent elements.
///
/// The result always has one element less than this list,
/// if this list has any elements.
List<R> combinePairs<R>(R Function(T, T) combine) =>
[for (int i = 1; i < this.length; i++)
combine(this[i - 1], this[i])];
}
```
Extension declarations cannot declare instance fields or
constructors.
Extension members can be invoked explicitly,
`MyFancyList(intList).isLengthEven)`,
or implicitly, `intList.isLengthEven`,
where the latter is recognized by `intList` matching the `List<T>`
"on" type of the declaration.
An extension member cannot be called implicitly on an expression
whose static type has a member with the same base-name.
In that case, the interface member takes precedence.
If multiple extension members apply to the same implicit
invocation, the most specific one is used, if there is one such.
Extensions can be declared on any type, not just interface types.
```dart
extension IntCounter on int {
/// The numbers from this number to, but not including, [end].
Iterable<int> to(int end) sync* {
int step = end < this ? -1 : 1;
for (int i = this; i != end; i += step) yield i;
}
}
extension CurryFunction<R, S, T> on R Function(S, T) {
/// Curry a binary function with its first argument.
R Function(T) curry(S first) => (T second) => this(first, second);
}
```
[Static extension members]: https://github.com/dart-lang/language/blob/master/accepted/2.6/static-extension-members/feature-specification.md
* **Breaking change** [#37985](https://github.com/dart-lang/sdk/issues/37985): * **Breaking change** [#37985](https://github.com/dart-lang/sdk/issues/37985):
Inference is changed when using `Null` values in a `FutureOr` context. Inference is changed when using `Null` values in a `FutureOr` context.
Namely, constraints of the forms similar to `Null` <: `FutureOr<T>` now Namely, constraints of the forms similar to `Null` <: `FutureOr<T>` now