Bug 18569 – std.traits.moduleName problem with enum
Status
RESOLVED
Resolution
DUPLICATE
Severity
minor
Priority
P1
Component
phobos
Product
D
Version
D2
Platform
All
OS
All
Creation time
2018-03-07T15:06:28Z
Last change time
2020-03-21T03:56:35Z
Assigned to
No Owner
Creator
Claude
Comments
Comment #0 by claudemr — 2018-03-07T15:06:28Z
How to reproduce the issue, 2 files containing the same code, only the module name changes.
aa.d:
module aa;
import std.traits : moduleName;
private enum stuff = 0;
pragma(msg, moduleName!stuff);
bb.d:
module bb;
import std.traits : moduleName;
private enum stuff = 0;
pragma(msg, moduleName!stuff);
Command line:
dmd aa.d bb.d -main
Output of the command line:
aa
aa
Whereas I would expect:
aa
bb
-------------
Replacing:
private enum stuff = 0;
with:
private int stuff = 0;
gives a proper result.
Replacing:
private struct stuff { };
with:
private struct stuff { };
also gives a proper result.
It does not look like it comes from the "parent" traits, as using:
private enum stuff = 0;
pragma(msg, __traits(parent, stuff).stringof[7..$]);
also gives a proper result.
Comment #1 by claudemr — 2018-03-07T15:13:18Z
Actually it is not certain that is a Phobos problem, as replacing the moduleName template within std.traits by that reduced code:
template moduleName(alias A)
{
// __traits(parent) returns "module modName"
// so we just retreive "modName"
enum moduleName = (__traits(parent, A).stringof)[7 .. $];
}
... leads to a wrong result (ignoring the fact package names are not prepended to the module name in that code of course, which is not the issue here anyway).
Comment #2 by b2.temp — 2018-08-20T12:15:06Z
Strange issue indeed. HAR on run.dlang.io with different symbol names also gives the same result !
https://run.dlang.io/is/VTCiI5
Comment #3 by ag0aep6g — 2018-08-20T12:28:12Z
*** This issue has been marked as a duplicate of issue 14501 ***