Control Invocation: proposal for simplification

Gernot Neppert mcnepp02 at googlemail.com
Tue Jan 5 00:49:11 PST 2010


Hello,

I have a proposal to simplify the Control Invocation syntax. It
consists of two parts:

1. Limit the difficulties with non-local transfer to "return",
eliminating "break" and "continue".

2. Waive transparency of "return" in lambdas.

In order to limit non-local transfer issues to "return", I suggest
scrapping the "for-loop abstraction syntax" altogether.
This will make all issues with top-level "breaks" and "continues"
within lambdas disappear, since the compiler will flag them as the
usual error.
To me, the examples provided so far for new loop-constructs are unconvincing.
I think the enhanced for-syntax of Java 5 provides enough convenience
for almost all usecases.

This leaves us with the normal Control Invocation syntax (A method
having a lambda type returning void as its last argument may be
invoked as if it one less argument, followed by a block that
constitutes the lambda).

My proposal: if the compiler spots such a construct, it should issue a
diagnostic if the lamba-block contains a "return".
The message should be something like "return will leave the innermost
block only", suppressable via @SuppressWarning("local-return")


Here's an example using the declaration of "with" from section 0.6b
that will trigger the diagnostic:


with(FileReader in : makeReader())  {
    // code using in
   return;
}

This invocation, however, will not trigger the diagnostic:

with(makeReader() , #void(FileReader in) {
    // code using in
   return;
});


More information about the closures-dev mailing list