digitalmars.D - __traits(allMembers) includes weird symbols for structs with tuples
- Steven Schveighoffer (32/32) Apr 08 2021 This:
- H. S. Teoh (10/28) Apr 08 2021 [...]
- Steven Schveighoffer (3/4) Apr 08 2021 https://issues.dlang.org/show_bug.cgi?id=21812
- user1234 (9/20) Apr 08 2021 Bug.
This: ```d struct S(A...) { A args; } void main() { pragma(msg, __traits(allMembers, S!(int, float))); } ``` outputs this: ``` tuple("args", "__args_field_0", "__args_field_1") ``` What happens if you try to access __args_field_0, etc? ```d void main() { S!(int, float) s; import std.stdio; writeln(s.__args_field_0); // Error: no property __args_field_0 for type S!(int, float) writeln(__traits(getMember, s, "__args_field_0")); // same error pragma(msg, __traits(identifier, __traits(getMember, typeof(s), "__args_field_0"))); // same error } ``` Why is __traits(allMembers) returning things that aren't members in any way, shape or form? Bug? -Steve
Apr 08 2021
On Thu, Apr 08, 2021 at 08:15:10PM -0400, Steven Schveighoffer via Digitalmars-d wrote: [...]```d void main() { S!(int, float) s; import std.stdio; writeln(s.__args_field_0); // Error: no property __args_field_0 for type S!(int, float) writeln(__traits(getMember, s, "__args_field_0")); // same error pragma(msg, __traits(identifier, __traits(getMember, typeof(s), "__args_field_0"))); // same error } ``` Why is __traits(allMembers) returning things that aren't members in any way, shape or form? Bug?[...] I suspect it's returning internal compiler implementation details that aren't supposed to be accessible to user code. That, or introspecting this particular type was overlooked when this was implemented. I'd file an issue in bugzilla. T -- There are 10 kinds of people in the world: those who can count in binary, and those who can't.
Apr 08 2021
On 4/8/21 8:32 PM, H. S. Teoh wrote:I'd file an issue in bugzilla.https://issues.dlang.org/show_bug.cgi?id=21812 -Steve
Apr 08 2021
On Friday, 9 April 2021 at 00:15:10 UTC, Steven Schveighoffer wrote:This: ```d struct S(A...) { A args; } [...] Why is __traits(allMembers) returning things that aren't members in any way, shape or form? Bug? -SteveBug. Even if args is usually only designed to be called using an IndexExp what appens is that for each tuple element a VarDecl is created. Those declarations are not added to the scope symtab. Adding them to the symtab makes your example to compile and I think that it's a better solution than filtering allMembers results as a special case is avoided.
Apr 08 2021