Circular enum member references in UDAs

realhet real_het at hotmail.com
Thu Feb 15 18:12:42 UTC 2024


Hello,

Today I tried to upgrade my sources to the latest LDC, but failed 
with this unfortunate error.

```
import std;

struct S{ E e; }

enum E
{
     @S(e2) e1,
     @S(e1) e2
}

void main() {
	E.e1.writeln;
}
```

It only runs in DMD 2.086.1 to 2.101.2

I can only think that the compiler changed from two pass lazy 
interpretation down to a single pass.  So when it finds the very 
first attribute "@S(e2)" it immediately wants to lookup the 
member e2 and fails.

I really liked this feature because it was so compact. I was able 
to define a state-graph used to parse the structure of almost any 
DLang source files.
This way the structure of the D language can be defined on 1 page 
in D language itself.

[https://ibb.co/HFWR2Qg](https://ibb.co/HFWR2Qg)

Is there a better practice to do this?  All else I can think of 
that the graph-nodes and the graph-edges are declared separately, 
that would be more redundant.  This self-referencing way was the 
only way to declare them in-place.


More information about the Digitalmars-d-learn mailing list