Any good ideas how to do that?

I couldn't figure it out in a short amount of time, but I expect that it's possible. I'm probably missing something obvious here. Probably because D's reflection/meta programming facilities are a bit all over the place (and unnecessarily convoluted IMO). Also I'm not super familiar with every compile-time feature, which is why I want to learn and some meta functions/templates myself.

In my usecase I want to extract structs with UDAs from a module, which also imports bunch of stuff. Now __traits(allMembers) gives me the list of things (in strings) that the module contains. This includes module imports and when I do something like this (in pseudo D):

template
{
  foreach(name ; __traits(allMembers, MODULE) )
foreach(attr_name ; __traits(getAttributes, __traits(getMember, MODULE, name)))
      whatever logic...
}

I get "Deprecation: foo.bar is not visible from module baz" with 2.071+ compiler (i.e. import symbol lookup rules changed) where foo.bar is an import in MODULE and baz is the module where the template for code above is located. And I'm calling the template from yet another module qux. This used to work with previous versions (modules were just skipped). The trouble begins when an import module is passed to __traits(getMember). (however I can do __traits(hasMember) which is a bit weird, since I'd assume same visibility rules would apply).

Here's a pseudo example:

mymodule.d:
import foo.bar;
@uda
struct mystruct

baz.d
template get_uda_structs

qux.d
import mymodule.d
import baz.d
auto structs = get_uda_structs(mymodule, uda); // Won't compile: "Deprecation: foo.bar is not visible from module baz"

Reply via email to