[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
https://issues.dlang.org/show_bug.cgi?id=16015
--- 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:
test1.d
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;
unittest{
auto mine = mystruct!int(2);
auto another = anotherstruct(2);
another.testmethod(0); // compiles
another.testmethod(mine); // does not compile
}
test2.d
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:
E:\Dropbox\Projects\d\misc\test1.d(6):
test1.anotherstruct.testmethod(const(int) x)
Failed: ["dmd", "-IE:/Dropbox/Projects/d", "-debug", "-g", "-unittest",
"-v", "-o-", "E:\\Dropbox\\Projects\\d\\misc\\test1.d",
"-IE:\\Dropbox\\Projects\\d\\misc"]
[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