Quantum Superposition Observed in DMD at Compile Time

Jonathan M Davis newsgroup.d at jmdavisprog.com
Tue Jul 2 17:10:34 UTC 2019


On Tuesday, July 2, 2019 8:44:38 AM MDT Ataide via Digitalmars-d wrote:
> On Monday, 1 July 2019 at 05:57:25 UTC, John Colvin wrote:
> > Here's a simpler example...
>
> Sorry to disturb here, but I tried to post over Learn but got a
> Forum error.
>
> Could you tell me why I am getting error on this code:
>
> //DMD64 D Compiler 2.072.2
> import std.stdio;
> void main(){
>    static foreach(i;[1,2,3]){}
> }
>
> Error(s):
> source_file.d(4): Error: basic type expected, not foreach
> source_file.d(4): Error: no identifier for declarator _error_
>
> Thanks.

Well, static foreach wasn't implemented until 2.076, so putting static in
front of foreach like that would be illegal with 2.072.2. The fact that
_error_ shows up in the message like that indicates a bug with how dmd dealt
with the error (probably an issue with lowering), but the code isn't legal
prior to 2.076. At that point, you would have had to iterate over an
AliasSeq to force the foreach to be done at compile time.

- Jonathan M Davis





More information about the Digitalmars-d mailing list