New __traits
Daniel Murphy via Digitalmars-d
digitalmars-d at puremagic.com
Wed Nov 25 07:39:20 PST 2015
On 25/11/2015 12:06 PM, BLM768 wrote:
> For a project I've been working on, I found that it would be helpful to
> have a way to determine whether a symbol represents a module or package.
> Since I couldn't find an easy way to do it, I forked DMD and made some
> tweaks. ;)
>
> Anyway, I uncovered an interesting issue. According to my test program
> (https://gist.github.com/blm768/42f40aa5a0c49bb8bd16), these are the
> "types" of various packages/modules in Phobos:
> std:
> std.stdio: package, module
> std.algorithm: package
> std.digest: package
>
> In other words, "std" isn't a package _or_ module, and std.stdio is both
> (even though it's just a single D source file). This doesn't seem quite
> right.
>
> There could be an error in my patch to DMD, but I don't see where it
> could be because it's so simple. The code is at
> https://github.com/blm768/dmd/tree/new_traits if anyone wants to look
> over it.
>
> If anyone can help me figure out what's going on, I'd greatly appreciate
> it.
What you're seeing is just an artifact of how dmd's internals work.
'std' is an 'import' (call Dsymbol.kind() for the category of symbol)
and you'll have to resolve it to work out which module/package is being
imported. It's possible that this is a bug in the symbol resolution,
and that it should have already been resolved to a package.
Keep in mind also that isPackage and isModule are RTTI functions, and
since Module inherits from Package all modules will appear to be
packages if that's all you check.
More information about the Digitalmars-d
mailing list