CT foreaches

Nick Treleaven nick at geany.org
Fri Aug 1 16:45:04 UTC 2025


On Friday, 1 August 2025 at 15:47:47 UTC, monkyyy wrote:
> On Friday, 1 August 2025 at 15:15:35 UTC, Nick Treleaven wrote:
>> 
>> Up to here is all as expected, right?
>
> No, `foreach(alias` is functionally undocumented

Thanks, fix:
https://github.com/dlang/dlang.org/pull/4279

>>> 	pragma(msg,"---");
>>> 	foreach(enum i;0..3){// ERROR ISNT CT. ISNT AN ENUM
>>> 		pragma(msg, i.stringof);
>>> 		//foo!i; //doesnt compile
>>
>> You're using runtime foreach here. It's only expanded at 
>> compile-time when the aggregate is a sequence - as the spec 
>> says.
>>
>
> `foreach(enum i;0..3){` is directly from the dip 1010 its

That's under the 'Limitations of this DIP / possible future 
improvements' section:
https://github.com/dlang/DIPs/blob/master/DIPs/accepted/DIP1010.md#allowing-alias-and-enum-on-regular-foreach-loop-variables

> unclear from the responce if it was accepted or rejected

That DIP says 'Status: 	Accepted' at the top.

>>> b) enum or alias of aliasSeq, whoever made thought there be 
>>> an upgrade to fully generalize the syntax
>>
>> Not sure what you mean for (b).
>
> dip 1010 was optimistic about near term upgrades to static 
> foreach; static break and continue
>
> ---
>
>> The confusing thing is that enum there is silently ignored. I 
>> think we could add an error for that.
>
> That would be a breaking change now, most code swapped from 
> runtime to ct should continue working tho, better to just 
> implement it

Not really, no one should have used enum/alias with a non-static 
ForeachRangeStatement because (as you pointed out), it wasn't in 
the spec. If they did use it, they'd probably realize that those 
storage classes had no effect.



More information about the Digitalmars-d mailing list