[Issue 16015] Sometimes importing a module both top-level and in a version(unittest) block causes some method overrides to be hidden

via Digitalmars-d-bugs digitalmars-d-bugs at puremagic.com
Wed May 11 15:28:02 PDT 2016


--- Comment #2 from Sophie <meapineapple at gmail.com> ---
I was able to reproduce this error on Windows 7 and will try this specific test
on OSX Mavericks soon, but I expect the problem is not present on OSX.

Testing this requires two files:


    import test2 : mystruct;
    import std.stdio : writeln;

    struct anotherstruct{
        int y = 0;
        void testmethod(in int x){
            writeln(x * this.y);
        void testmethod(T)(in mystruct!T my){
            writeln(my.x * this.y);

    version(unittest) import test2 : mystruct;
        auto mine = mystruct!int(2);
        auto another = anotherstruct(2);
        another.testmethod(0); // compiles
        another.testmethod(mine); // does not compile


    struct mystruct(T){T x;}

This is the resulting error:

    E:\Dropbox\Projects\d\misc\test1.d(19): Error: none of the overloads of
'testmethod' are callable using argument types (mystruct!int), candidates are:
test1.anotherstruct.testmethod(const(int) x)
    Failed: ["dmd", "-IE:/Dropbox/Projects/d", "-debug", "-g", "-unittest",
"-v", "-o-", "E:\\Dropbox\\Projects\\d\\misc\\test1.d",
    [Finished in 0.3s with exit code 1]
    [shell_cmd: rdmd -odbin/ -I"E:/Dropbox/Projects/d" -debug -g --main
-unittest "E:\Dropbox\Projects\d\misc\test1.d"]

If mystruct is not templated, then sensible descriptive errors occur letting me
know that I've aliased the imported "mystruct" twice, and if without the
template I just "import test2;" then everything compiles fine.

Removing "version(unittest) import test2 : mystruct;" from test1.d also allows
the problematic line to compile.


More information about the Digitalmars-d-bugs mailing list