Mutually recursive template expansion

Basile B. b2.temp at gmx.com
Sat Oct 2 09:56:55 UTC 2021


On Saturday, 2 October 2021 at 08:48:24 UTC, Stephen wrote:
> Is this by design?

No but it's easily explainable.

## without mixins

```d
struct Ar { Br b; ubyte a; }
struct Br { ubyte b; }
```

`Ar` semantic starts, members are analyzed, that begins with the 
variable declaration `Br b`. `Br` type needs to be resolved. `Br` 
can be found in the AST as it is declared manually. Now `Br` is 
run and finally `Ar` sema continues.

## with mixins

```d
mixin(q{struct Ar { Br b; ubyte a; }});
mixin(q{struct Br { ubyte b; }});
```

The first mixin is compiled (`compileIt()` in dmd code base).

The AST is now the same as obtained by parsing

```d
struct Ar { Br b; ubyte a; }
mixin(q{struct Br { ubyte b; }});
```

`Ar` semantic starts, members are analyzed, that begins with the 
variable declaration`Br b`. But `Br` cannot be resolved because 
**it is not yet in the AST** and the symbol tables.


More information about the Digitalmars-d-learn mailing list