Spec draft for JEP 286 Local Variable Type Inference
Dan Smith
daniel.smith at oracle.com
Thu Mar 30 17:04:36 UTC 2017
> On Mar 29, 2017, at 11:13 PM, Ali Ebrahimi <ali.ebrahimi1781 at gmail.com> wrote:
>
> Hi Dan,
> I don't ask to add inference support for array initializer expressions: var f = { 1 };
> But I think there is an inconsistency in 14.14.2 wrt. array initializer expressions:
> The current spec supports this:
> for(var i : {1, 2.0}) ...
> Is this intended?
Thanks for the comment.
I think you're missing something in the 14.14.2 grammar: the _VariableDeclaratorId_ is followed by an _Expression_. While _ArrayInitializer_ is expression-like, it's not actually treated as an _Expression_ by the grammar (see 10.6, 15.2, 15.10.1). So your 'for' loop above has a syntax error.
Contrast this with _VariableDeclarator_ (8.3), which explicitly allows the initializer to be an _Expression_ or an _ArrayInitializer_.
(Aside: eventually, we'd love to allow this syntax in more places, as a poly expression. JEP 186 is probably the vehicle for that change, but for now we've set it aside [1].)
—Dan
[1]: http://mail.openjdk.java.net/pipermail/lambda-dev/2014-March/011938.html
More information about the amber-spec-observers
mailing list