for-loops and declaration-like init expressions

Mark S. Miller erights at google.com
Thu Jun 5 08:44:55 PDT 2014


Hi John, for those it is unsurprising that they would be allowed, and that
they would be taken as expressions rather than declarations.


On Thu, Jun 5, 2014 at 8:23 AM, John Lenz <concavelenz at gmail.com> wrote:

> Would this still be legal, in this scheme?
>
>   for ((function x(){}); ;) x  // 0
>   for ((class x(){}); ;) x  // 0
>
>
>
> On Thu, Jun 5, 2014 at 7:58 AM, Andreas Rossberg <rossberg at google.com>
> wrote:
>
>> C-style for-loops allow declarations as init statements, but only some
>> of them. Yet, the others (function and class) are actually
>> syntactically legal in that position as well, because they are simply
>> parsed as expressions. Consider:
>>
>>   let x = 0
>>   for (let x = 1; ;) x  // 1
>>   for (const x = 1; ;) x  // 1
>>   for (function x(){}; ;) x  // 0
>>   for (class x(){}; ;) x  // 0
>>
>
>
>> I think these latter two examples violate the principle of least
>> surprise. I wonder if it wouldn't be cleaner to rule them out, by
>> imposing the same lookahead restrictions on for-loop init expressions
>> as there are for expression statements.
>>
>> The one caveat is that for function, that would actually be a breaking
>> change, but is it likely to be a real world one?
>>
>> What do you think?
>>
>> /Andreas
>> _______________________________________________
>> es-discuss mailing list
>> es-discuss at mozilla.org
>> https://mail.mozilla.org/listinfo/es-discuss
>>
>
>
> _______________________________________________
> es-discuss mailing list
> es-discuss at mozilla.org
> https://mail.mozilla.org/listinfo/es-discuss
>
>


-- 
    Cheers,
    --MarkM
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.mozilla.org/pipermail/es-discuss/attachments/20140605/dfad3fa6/attachment-0001.html>


More information about the es-discuss mailing list