Thread overview
Can't access enum from a different module when it was generated by a string mixin.
1 day ago
realhet
1 day ago
realhet
1 day ago
realhet
1 day ago
realhet
1 day ago
realhet
1 day ago

Hello,

I have a module with an enum declaration: module a; enum E:ubyte{ e1, e2 }

I can import it into a different module: module b; import a : E;

But if I generate the enum with a string mixin: module a; mixin(q{enum E:ubyte{ e1, e2 }});

I get an error: module a import E not found.

My question is: Why? And how to fix it? It prevents me from splitting into smaller modules.

These are just metadata, I don't want to use static immutable arrays, an enumerated tyope would be perfect. And it's a string mixin because I automatically generate it from an 'excel' table.

Thank You in advance!

1 day ago

On Monday, 31 March 2025 at 13:24:11 UTC, realhet wrote:

>

Hello,

I have a module with an enum declaration: module a; enum E:ubyte{ e1, e2 }

I can import it into a different module: module b; import a : E;

But if I generate the enum with a string mixin: module a; mixin(q{enum E:ubyte{ e1, e2 }});

I get an error: module a import E not found.

My question is: Why? And how to fix it? It prevents me from splitting into smaller modules.

These are just metadata, I don't want to use static immutable arrays, an enumerated tyope would be perfect. And it's a string mixin because I automatically generate it from an 'excel' table.

Thank You in advance!

Can you give a repro? It works here.

1 day ago

On Monday, 31 March 2025 at 13:24:11 UTC, realhet wrote:

>

Hello,

Update: One ugly workaround I've found is to put a dummy struct around the string mixin, but that introduces unwanted redundancy.

It seems like only module level enum type declarations are lost if they were mixed in.

1 day ago

On Monday, 31 March 2025 at 14:59:21 UTC, FeepingCreature wrote:

>

Can you give a repro? It works here.

You are right, I just tested in small scale and it worked.

module a;

enum EGood:ubyte {e1, e2}

mixin(q{enum EBad:ubyte {e1, e2} });

struct Dummy { mixin(q{enum EUgly:ubyte {e1, e2} }); }
alias EUgly = Dummy.EUgly;
module b;

import std, a;

void main()
{
	writeln(EGood.init);
	writeln(EBad.init);   //In the big project, this fails.
	writeln(EUgly.init);
}

I have the problem in an 50KLOC project. I gotta narrow it down...

1 day ago

On Monday, 31 March 2025 at 14:59:21 UTC, FeepingCreature wrote:

>

On Monday, 31 March 2025 at 13:24:11 UTC, realhet wrote:
Can you give a repro? It works here.

Ok, I tried and gave up, it's too big.

But I've found what is triggering it. The problem roots in circular module imports, and this mixin(enum) thing is just a symptom. So it was a false alarm from me, please ignore.


I have no clue, how to turn this into a clean tree with no circular references...

Until that I will put these mixed in enums into a struct. That's something like an atomic unit, not like the surface of a module which is optionally and lazily evaluated by many compiler passes I don't have much knowledge of.

1 day ago

On Monday, 31 March 2025 at 17:21:03 UTC, realhet wrote:

>

On Monday, 31 March 2025 at 14:59:21 UTC, FeepingCreature wrote:

>

On Monday, 31 March 2025 at 13:24:11 UTC, realhet wrote:

Forgot the picture link:
https://ibb.co/1GXKvfQz

I'm kinda abusing the circular import feature.
When I put 10-20K lines into big modules, it's easier for the compiler, but that can go out of hand, difficult to maintain.