D issues are now tracked on GitHub. This Bugzilla instance remains as a read-only archive.
Issue 6910 - __traits(hasMember, "<name>") does not work, if template has alias param
Summary: __traits(hasMember, "<name>") does not work, if template has alias param
Status: RESOLVED FIXED
Alias: None
Product: D
Classification: Unclassified
Component: dmd (show other issues)
Version: D2
Hardware: All All
: P2 normal
Assignee: No Owner
URL:
Keywords: patch, wrong-code
Depends on:
Blocks:
 
Reported: 2011-11-08 14:29 UTC by Tobias Pankrath
Modified: 2015-06-09 05:11 UTC (History)
1 user (show)

See Also:


Attachments

Note You need to log in before you can comment on or make changes to this issue.
Description Tobias Pankrath 2011-11-08 14:29:58 UTC
Given this code fragment:

--------------
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;
}
----------------------

DMD will output:
----------------------
tuple("m")
false
---------------------

It seems that __traits(hasMember, ..) evaluates to false, despite the fact that the type 
does have a member "m". However if the template Test does not have an alias parameter, everything will work just fine.
Comment 1 Kenji Hara 2011-11-12 08:43:48 UTC
I think this is an issue that both of D1 and D2 have.

D2 patch:
https://github.com/D-Programming-Language/dmd/pull/509