Skip to content

Commit 1cc2fb7

Browse files
floitschGdgrove
authored andcommitted
Add a changelog entry for the function-type syntax.
Fixes #27527 BUG= http://dartbug.com/27527 [email protected] Review-Url: https://codereview.chromium.org/2906453002 .
1 parent f95c797 commit 1cc2fb7

File tree

1 file changed

+25
-0
lines changed

1 file changed

+25
-0
lines changed

CHANGELOG.md

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,30 @@
88
type `void` now allows the returned expression to have any type. For example,
99
assuming the declaration `int x;`, it is now type correct to have
1010
`void f() => ++x;`.
11+
* A new function-type syntax has been added to the language.
12+
Intuitively, the type of a function can be constructed by textually replacing
13+
the function's name with `Function` in its declaration. For instance, the
14+
type of `void foo() {}` would be `void Function()`. The new syntax may be used
15+
wherever a type can be written. It is thus now possible to declare fields
16+
containing functions without needing to write typedefs: `void Function() x;`.
17+
The new function type has one restriction: it may not contain the old-style
18+
function-type syntax for its parameters. The following is thus
19+
illegal: `void Function(int f())`.
20+
`typedefs` have been updated to support this new syntax.
21+
Examples:
22+
```
23+
typedef F = void Function(); // F is the name for a `void` callback.
24+
int Function(int) f; // A field `f` that contains an int->int function.
25+
26+
class A<T> {
27+
// The parameter `callback` is a function that takes a `T` and returns
28+
// `void`.
29+
void forEach(void Function(T) callback);
30+
}
31+
32+
// The new function type supports generic arguments.
33+
typedef Invoker = T Function<T>(T Function() callback);
34+
```
1135

1236
#### Strong Mode
1337

@@ -24,6 +48,7 @@ entirely to allow inference to fill in the type.
2448
* The following is also a change in strong mode: During static analysis, a
2549
function or setter declared using `=>` with return type `void` now allows the
2650
returned expression to have any type.
51+
* The new function-type syntax is also supported by strong mode.
2752

2853
### Core library changes
2954

0 commit comments

Comments
 (0)