www.digitalmars.com         C & C++   DMDScript  

digitalmars.D.bugs - [Issue 19303] New: hasMember fails to recognize member (interaction


          Issue ID: 19303
           Summary: hasMember fails to recognize member (interaction with
                    mixin template)
           Product: D
           Version: D2
          Hardware: x86
                OS: Mac OS X
            Status: NEW
          Severity: enhancement
          Priority: P1
         Component: phobos
          Assignee: nobody puremagic.com
          Reporter: luis luismarques.eu

In the code quoted below, there is an inconsistency between these two lines:

    pragma(msg, P.ElementType);
    static assert(hasMember!(P, "ElementType"));

The pragma correctly prints the P.ElementType, but the hasMember assert fails.
The interaction with the mixin template suggests this might be a compiler bug,
but for now I'm only marking this as a Phobos bug. A workaround would be


import std.traits;

void main()
    alias V = Vec!Bool;
    alias P = Port!(V);
    pragma(msg, P.ElementType);
    static assert(hasMember!(P, "ElementType"));

mixin template SignalOps()
    static if(hasMember!(typeof(this), "ElementType")) { }

struct Bool {}

struct Port(SomeSignal)
    mixin SignalOps;

    static if(hasMember!(SomeSignal, "ElementType"))
        alias ElementType = SomeSignal.ElementType;

struct Vec(SomeSignal)
    alias ElementType = SomeSignal;

Oct 12 2018