The lambda conversion and a lambda body that doesn't complete.

Ben Evans benjamin.john.evans at gmail.com
Wed Mar 2 09:09:58 PST 2011


OK, I'll bite.

What's the interest in this use case?

As I read it, you're saying that if the compiler can provably guarantee that
a lambda cannot return normally, then the compiler should ignore the return
type when SAM-converting. Is that the property we're after?

What's the use case for this feature? How often are we actually going to
write code inside a lambda which the compiler can guarantee will not return
normally? Should we even be encouraging people to write code like that?

Glaringly obvious use cases and other smackdown in 3-2-1.... :)

Ben

On Tue, Mar 1, 2011 at 5:35 PM, Neal Gafter <neal at gafter.com> wrote:

> Dear Lambdans-
>
> Given
>
> *interface F {
>    int invoke();
> }*
>
> I would like to be able to write
>
> *F x = #{ throw new Exception(); };
> *
>
> (Modulo syntax - whatever the current syntax is)
>
> But according to the current draft specification that's not allowed (the
> lambda as written can only be converted to a SAM with a void return type).
>
> I think that whether or not the lambda's body can complete normally should
> be taken into account in the lambda conversion to make this legal.  As a
> point of information, the behavior I prefer is the behavior of Scala, BGGA,
> and C# (among others).  This is also consistent with the way method
> implementations work:
>
> *int f() { throw new Exception(); }*
>
> In the unfortunate case that you need use cases for this, draft
> specification language, or suggestions for a straightforward
> implementation,
> I can provide those.
>
> Cheers,
> Neal
>
>


More information about the lambda-dev mailing list