[Issue 15086] import doesn't verify module declaration

d-bugmail at puremagic.com d-bugmail at puremagic.com
Wed Feb 14 05:18:22 UTC 2018


https://issues.dlang.org/show_bug.cgi?id=15086

--- Comment #24 from Jonathan Marler <johnnymarler at gmail.com> ---
> I have not thought about this thoroughly, but I suspect the core of a fix can be along the lines of detecting that an explicit import of bar.d is done using two different names in the same module.

After having a bit of a think I realized this still doesn't solve the problem. 
I can change the example to show that module order also changes
compilation...observe:

--- main.d
import ibar, ibaz;
void main()
{
    ibarfunc();
    ibazfunc();
}

--- ibar.d
import bar, std.stdio;
void ibarfunc()
{
    writeln(thing);
}

--- ibaz.d
import baz, std.stdio;
void ibazfunc()
{
    writeln(thing);
}

--- bar.d
module baz;
enum thing = "this is baz from bar.d";

--- baz.d
module bar;
enum thing = "this is bar from baz.d";


dmd ibar.d ibaz.d -run main.d
OUTPUT:
this is baz from bar.d
this is baz from bar.d

dmd ibaz.d ibar.d -run main.d
OUTPUT:
this is bar from baz.d
this is bar from baz.d


Note that in the case the same module is not imported with different names in
the same file.  So fixing that won't fix this issue.

--


More information about the Digitalmars-d-bugs mailing list