mirror of
https://github.com/dart-lang/sdk
synced 2024-10-01 19:29:09 +00:00
Add a changelog entry for the function-type syntax.
Fixes #27527 BUG= http://dartbug.com/27527 R=leafp@google.com Review-Url: https://codereview.chromium.org/2906453002 .
This commit is contained in:
parent
03688818fa
commit
e9e9835afc
25
CHANGELOG.md
25
CHANGELOG.md
|
@ -8,6 +8,30 @@
|
||||||
type `void` now allows the returned expression to have any type. For example,
|
type `void` now allows the returned expression to have any type. For example,
|
||||||
assuming the declaration `int x;`, it is now type correct to have
|
assuming the declaration `int x;`, it is now type correct to have
|
||||||
`void f() => ++x;`.
|
`void f() => ++x;`.
|
||||||
|
* A new function-type syntax has been added to the language.
|
||||||
|
Intuitively, the type of a function can be constructed by textually replacing
|
||||||
|
the function's name with `Function` in its declaration. For instance, the
|
||||||
|
type of `void foo() {}` would be `void Function()`. The new syntax may be used
|
||||||
|
wherever a type can be written. It is thus now possible to declare fields
|
||||||
|
containing functions without needing to write typedefs: `void Function() x;`.
|
||||||
|
The new function type has one restriction: it may not contain the old-style
|
||||||
|
function-type syntax for its parameters. The following is thus
|
||||||
|
illegal: `void Function(int f())`.
|
||||||
|
`typedefs` have been updated to support this new syntax.
|
||||||
|
Examples:
|
||||||
|
```
|
||||||
|
typedef F = void Function(); // F is the name for a `void` callback.
|
||||||
|
int Function(int) f; // A field `f` that contains an int->int function.
|
||||||
|
|
||||||
|
class A<T> {
|
||||||
|
// The parameter `callback` is a function that takes a `T` and returns
|
||||||
|
// `void`.
|
||||||
|
void forEach(void Function(T) callback);
|
||||||
|
}
|
||||||
|
|
||||||
|
// The new function type supports generic arguments.
|
||||||
|
typedef Invoker = T Function<T>(T Function() callback);
|
||||||
|
```
|
||||||
|
|
||||||
#### Strong Mode
|
#### Strong Mode
|
||||||
|
|
||||||
|
@ -24,6 +48,7 @@ entirely to allow inference to fill in the type.
|
||||||
* The following is also a change in strong mode: During static analysis, a
|
* The following is also a change in strong mode: During static analysis, a
|
||||||
function or setter declared using `=>` with return type `void` now allows the
|
function or setter declared using `=>` with return type `void` now allows the
|
||||||
returned expression to have any type.
|
returned expression to have any type.
|
||||||
|
* The new function-type syntax is also supported by strong mode.
|
||||||
|
|
||||||
### Core library changes
|
### Core library changes
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue