www.digitalmars.com         C & C++   DMDScript  

digitalmars.D.learn - Is this a bug in __traits(hasMember..)?

reply Tobias Pankrath <tobias pankrath.net> writes:
Please take a look at this code

--------------------
struct Bag(S...)
{
    alias S Types;
}

template Test(alias i, B)
{
    void fn() {
        foreach(t; B.Types)
        {
            switch(i) {
                case IndexOf!(t, B.Types):
                {
                    pragma(msg, __traits(allMembers, t));
                    pragma(msg, __traits(hasMember, t, "m"));
                    break;
                }
                default: {}
            }

        }
    }
}

struct A
{
    int m;
}


void main()
{

    int i;
    alias Test!(i, Bag!(A)).fn func;
}
-----------------

If I compile this, DMD will print
------------------
dmd test.d 
tuple("m")
false
------------------

which is very confusing to me. Guess this is a bug?

Tobias
Nov 08 2011
parent reply Robert Clipsham <robert octarineparrot.com> writes:
On 08/11/2011 20:09, Tobias Pankrath wrote:
 which is very confusing to me. Guess this is a bug?

 Tobias

Looks like a bug to me. This works: ---- struct Bag(S...) { alias S Types; } template Test(/*alias i,*/ B) { void fn() { foreach(t; B.Types) { pragma(msg, t.stringof); pragma(msg, __traits(allMembers, t)); pragma(msg, __traits(hasMember, t, "m")); } } } struct A { int m; } void main() { /*int i;*/ alias Test!(/*i,*/ Bag!(A)).fn func; } ---- But if you uncomment everything I've commented then it fails. Definitely worth a bug report when you have time - http://d.puremagic.com/issues/ -- Robert http://octarineparrot.com/
Nov 08 2011
parent Tobias Pankrath <tobias pankrath.net> writes:
http://d.puremagic.com/issues/show_bug.cgi?id=6910
Nov 08 2011