How compiler detects forward reference errors

Stefan Koch via Digitalmars-d-learn digitalmars-d-learn at puremagic.com
Sat Sep 3 07:23:35 PDT 2016


On Saturday, 3 September 2016 at 14:06:06 UTC, Igor wrote:
> Can anyone explain in plain English how does compiler process 
> and detect a "test.d(6) Error: forward reference of variable a" 
> in following code:
>
> import std.stdio;
>
> enum a = 1 + b;
> enum d = 5 + a; // No error here
> enum b = 12 + c;
> enum c = 10 + a; // error here
>
> void main()
> {
>     writeln("Hello World!", b);
> }

This is an recursive expression.
c = 10 + 1 + 12 + c ...
and therefore cannot be compiled.


More information about the Digitalmars-d-learn mailing list