[Issue 19303] hasMember fails to recognize member (interaction with mixin template)
d-bugmail at puremagic.com
d-bugmail at puremagic.com
Wed Nov 28 10:12:54 UTC 2018
https://issues.dlang.org/show_bug.cgi?id=19303
Eduard Staniloiu <edi33416 at gmail.com> changed:
What |Removed |Added
----------------------------------------------------------------------------
CC| |edi33416 at gmail.com
--- Comment #1 from Eduard Staniloiu <edi33416 at gmail.com> ---
This is most definitely a compiler bug which seems to be related/triggered my
the template mixin, as `std.traits.hasMember` only calls the equivalent
`__traits(hasMember, T, memberName)` compiler trait.
As a workaround, you can use
static assert(__traits(hasMember, P, "ElementType")); // passes
Also, weirdly enough, swapping the mixin instantiation with the `static if`
block in `Port`, will pass the initial assert
```
struct Port(SomeSignal)
{
static if(hasMember!(SomeSignal, "ElementType"))
alias ElementType = SomeSignal.ElementType;
mixin SignalOps;
}
void main()
{
...
static assert(hasMember!(P, "ElementType")); // OK
static assert(__traits(hasMember, P, "ElementType")); // OK
}
```
You can check this on https://run.dlang.io/is/6aXcGq
--
More information about the Digitalmars-d-bugs
mailing list