April 06, 2021

Just encountered this compilation failure in DMD winx64 2.096, which previously worked in 2.095 and prior versions. Just wondering if it's a bug, or a new issue to keep in mind when importing modules? Sorry for the complex nature of this scenario but I'll try to keep it as simple as possible.

Given the following 4-file setup:

// main.d
import cream;
void main() {}

// cream/package.d
module cream;
public import cream.dcream;
public import cream.callbacks;

// cream/callbacks.d
module cream.callbacks;
import cream;
extern(C++) class CallbackBase {}

// cream/dcream.d
module cream.dcream;
import cream;
import std.container.array;
Array!CallbackBase callbackTracker;

Compilation fails with the following error:
C:\D\dmd2\windows\bin....\src\phobos\std\container\array.d(519): Error: incompatible types for array comparison: const(CallbackBase[]) and const(CallbackBase[])
C:\D\dmd2\windows\bin....\src\phobos\std\container\array.d(189): Error: template instance std.container.array.RangeT!(const(Array!(CallbackBase))) error instantiating
C:\D\dmd2\windows\bin....\src\phobos\std\container\array.d(528): instantiated from here: RangeT!(Array!(CallbackBase))
cream\dcream.d(4): instantiated from here: Array!(CallbackBase)

It seems I can fix this by changing the order the other modules are imported in package.d like so:
// cream/package.d
module cream;
public import cream.callbacks;
public import cream.dcream;

I'm curious why this worked in prior dmd versions, and if it's something I'll need to worry about going forward when creating complex multi-file modules.

April 06, 2021

On Tuesday, 6 April 2021 at 09:33:32 UTC, cc wrote:

>

Just encountered this compilation failure in DMD winx64 2.096, which previously worked in 2.095 and prior versions.

DMD 2.094.2 fails with the same error?
But current master works for me.

>

Just wondering if it's a bug, or a new issue to keep in mind when importing modules? Sorry for the complex nature of this scenario but I'll try to keep it as simple as possible.

That's a bug, ordering of import should never affect whether some code compiles or not.

>

I'm curious why this worked in prior dmd versions, and if it's something I'll need to worry about going forward when creating complex multi-file modules.

The ordering of imports can make a difference in some cases because it affects the order in which dmd analyses declarations - which might hide or reveal a bug.

Please file a bug report at https://issues.dlang.org if you encounter such issues.