www.digitalmars.com         C & C++   DMDScript  

digitalmars.D - Having problems using __traits

reply Daniel Ribeiro Maciel <danielmaciel gmail.com> writes:
Hello! I'm currently having this issue using __traits. Can anyone tell me what
am I doing wrong, or whether this is a compiler bug or not?
Thanks!

Source code is attached to this message.

S:\Repositorios\tpp\trunk\script.d(15): Error: string expected as second
argument of __traits getMember instead of method
S:\Repositorios\tpp\trunk\script.d(15): Error: function expected before (), not
false of type bool
S:\Repositorios\tpp\trunk\script.d(24): Error: template instance
script.exportType!(Test).exportType.methodHandler!(Test,method) error
instantiating
S:\Repositorios\tpp\trunk\script.d(30):        instantiated from here:
exportType!(Test)

Best Regards,
Daniel
Apr 03 2010
parent reply bearophile <bearophileHUGS lycos.com> writes:
Daniel Ribeiro Maciel:

 Hello! I'm currently having this issue using __traits. Can anyone tell me what
am I doing wrong, or whether this is a compiler bug or not?<
At the moment DMD2 has holes likes Swiss cheese. You have hit one, two, or more than two different bugs. This is the first bug: struct Test { void hello() {} } void main() { Test t; string m = "hello"; __traits(getMember, t, m)(); } The error message is wrong: if m must be an enum/immutable string, then the error message has to say so. The second problem can be seen here: import std.c.stdio: puts; class Test { void hello() { puts("hello!"); } } void methodHandler(T, alias member)() { auto o = new T(); __traits(getMember, o, member)(); } void main() { auto methods = __traits(allMembers, Test); foreach (method; methods) if (method == "hello") methodHandler!(Test, "hello")(); } If you replace "hello" inside methodHandler!(Test, "hello")(); with method, the program doesn't compile. I don't know if it's the same problem as before. I can put in bugzilla the first bug. Bye, bearophile
Apr 03 2010
parent bearophile <bearophileHUGS lycos.com> writes:
The first is now bug 4058. The second I don't know if it's the same bug...

Bye,
bearophile
Apr 03 2010