We added extensive support for treating a reference to a method as
a closure using a newly introduced token #
. The syntax
is borrowed from the FCM
proposal. The semantics are as follows:
A method reference written as
Primary # Identifier ( TypeList )
where the Primary designates an expression (as opposed to a type) is
treated the same as a closure
{ Type x0, Type x1 ... => tmp.Identifier(x0, x1 ...) }
or
{ Type x0, Type x1 ... => tmp.Identifier(x0, x1 ...); }
Where tmp is a temporary value that holds the computed value of the
primary expression. The former translation is used when the resolved
method has a non-void return type, while the latter is used when the
resolved method has a void return type.
If the primary resolves to a type, then this is translated to
{ Type x0, Type x1 ... => Primary.Identifier(x0, x1 ...) }
or
{ Type x0, Type x1 ... => Primary.Identifier(x0, x1 ...); }
when the resolved method is static, or
{ Primary x, Type x0, Type x1 ... => x.Identifier(x0, x1 ...) }
or
{ Primary x, Type x0, Type x1 ... => x.Identifier(x0, x1 ...); }
when the resolved method is an instance method.
In addition, optional explicit type arguments, between angle brackets,
may be placed immediately after the #
token. These are
used directly in the translated method invocation to resolve the
method to be invoked.