Mutually recursive template expansion

Stephen stephen.personal27 at gmail.com
Sat Oct 2 08:48:24 UTC 2021


On Friday, 1 October 2021 at 14:26:39 UTC, jfondren wrote:
> On Friday, 1 October 2021 at 14:03:06 UTC, Stephen wrote:
>> This code should work should mutual recursion be supported.
>
> It still wouldn't work, because structs are value types and 
> it's impossible to say how large either struct is:
>
> Error: struct `mutualrec.Ar` no size because of forward 
> reference
>
> With s/struct/class/ it still wouldn't work because this is a 
> mixin problem rather than a problem of template mutual 
> recursion:
>
> ```d
> mixin(q{ class Ar { Br b; } });
> mixin(q{ class Br { Ar b; } });
> ```
>
> mutualrec2.d-mixin-1(1): Error: undefined identifier `Br`, did 
> you mean class `Ar`?
>
> This seems like a surprising limitation of mixin, though, which 
> isn't highlighted by the spec.

All right I'll try to design without mutual recursion but mixins 
don't seem to work if they're put out of order.
(i.e. this works:
```d
struct Ar { Br b; ubyte a; }
struct Br { ubyte b; }
```
but not this:
```d
mixin(q{struct Ar { Br b; ubyte a; }});
mixin(q{struct Br { ubyte b; }});
```
).
Is this by design?


More information about the Digitalmars-d-learn mailing list