8
8
type ` void ` now allows the returned expression to have any type. For example,
9
9
assuming the declaration ` int x; ` , it is now type correct to have
10
10
` 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
+ ```
11
35
12
36
#### Strong Mode
13
37
@@ -24,6 +48,7 @@ entirely to allow inference to fill in the type.
24
48
* The following is also a change in strong mode: During static analysis, a
25
49
function or setter declared using ` => ` with return type ` void ` now allows the
26
50
returned expression to have any type.
51
+ * The new function-type syntax is also supported by strong mode.
27
52
28
53
### Core library changes
29
54
0 commit comments