package reflection

Shammah Chancellor via Digitalmars-d-learn digitalmars-d-learn at puremagic.com
Sun Jun 22 07:23:19 PDT 2014


On 2014-06-22 14:11:58 +0000, sigod said:

> In the video "Case Studies In Simplifying Code With Compile-Time 
> Reflection" [was pointed out][0] that it is possible to reflect on 
> imported packages.
> 
> So, I tried:
> 
> reflection.d:
> ```
> import std.stdio;
> 
> import test.module1;
> import test.module2;
> 
> void main() {
> 	foreach (m; __traits(allMembers, mixin(__MODULE__))) {
> 		writeln(m);
> 	}
> 
> 	writeln("--------------");
> 
> 	foreach (m; __traits(allMembers, test)) {
> 		writeln(m);
> 	}
> }
> ```
> 
> test/module1.d:
> ```
> module test.module1;
> 
> void module_1() {}
> ```
> 
> test/module2.d:
> ```
> module test.module2;
> 
> void module_2() {}
> ```
> 
> It produces:
> ```
> $ rdmd reflection.d
> object
> std
> test
> main
> --------------
> object
> module_1
> ```
> 
> As you see `module_2` wasn't listed. If I change order of import 
> declarations `module_2` will be listed instead of `module_1`.
> 
> I also tried to create `test/package.d` and publicly import other 
> modules through it, but it behave in the same way.
> 
> So, how to reflect on imported packages?
> 
> [0]: http://youtu.be/xpImt14KTdc?t=42m26s

This is very frustrating indeed, and I have an open bug request about 
it.     Please bump it so it gets some attention:

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

-Shammah



More information about the Digitalmars-d-learn mailing list