Generating code based on UDA
Ali Çehreli via Digitalmars-d-learn
digitalmars-d-learn at puremagic.com
Sat Oct 25 14:35:43 PDT 2014
On 10/25/2014 08:56 AM, Rares Pop wrote:
> Indeed it worked. What is the rationale behind the mixin(fullName) ?
__traits(getAttributes) requires a symbol but fullName is a string.
Mixing it in as code fulfills the requirement.
> However, in my project the injections function, the @Inject UDA struct
> and some other dependencies are defined in a library (libinfuse).
I am afraid it needs to be changed. :-/
> In this format the compiler gives the undefined identifier error I was
> mentioning in my first post.
> "source/infuse/injector.d-mixin-148(148): Error: undefined identifier B"
I found two solutions:
a) Do not define 'attributes' at all and use __traits(getAttributes)
directly in the foreach loop:
foreach (attr; __traits(getAttributes, mixin(fullName))) {
b) Define attributes as a typeof of __traits(getAttributes) and use that
in the foreach loop:
alias attributes = typeof(__traits(getAttributes, mixin(fullName)));
foreach (attr; attributes) {
I think what happens in both cases is that the entity that we iterate
over maintains its TypeTuple'ness without trying to produce a value out
of its members.
> Is this a dmd compiler bug?
I don't know but it is very confusing.
Ali
More information about the Digitalmars-d-learn
mailing list