[Issue 15094] New: __traits(getMember) fails when the source is a struct/class field
via Digitalmars-d-bugs
digitalmars-d-bugs at puremagic.com
Mon Sep 21 08:49:24 PDT 2015
https://issues.dlang.org/show_bug.cgi?id=15094
Issue ID: 15094
Summary: __traits(getMember) fails when the source is a
struct/class field
Product: D
Version: D2
Hardware: x86_64
OS: Linux
Status: NEW
Severity: normal
Priority: P1
Component: dmd
Assignee: nobody at puremagic.com
Reporter: initrd.gz at gmail.com
Attempting to use `__traits(getMember)` with a sub-struct/field fails with a
`need 'this'` error.
Example code:
import std.stdio;
struct Foo {
int i;
}
struct Bar {
Foo foo;
}
void main() {
Bar bar;
writeln(__traits(getMember, bar.foo, "i"));
}
Output:
$ rdmd ~/test.d
/home/col/test.d(14): Error: need 'this' for 'i' of type 'int'
Failed: ["dmd", "-v", "-o-", "/home/col/test.d", "-I/home/col"]
It's possible, but annoying, to work around this by storing a local pointer to
the field first.
auto foo = &bar.foo;
writeln(__traits(getMember, foo, "i"));
--
More information about the Digitalmars-d-bugs
mailing list