Bug 24227 – Add a trait to check if symbol is an alias

Status
NEW
Severity
enhancement
Priority
P1
Component
druntime
Product
D
Version
D2
Platform
All
OS
Windows
Creation time
2023-11-04T13:21:10Z
Last change time
2024-12-07T13:42:59Z
Assigned to
No Owner
Creator
Marcelo Silva Nascimento Mancini
Moved to GitHub: dmd#17467 →

Comments

Comment #0 by msnmancini — 2023-11-04T13:21:10Z
I have been trying to auto generate some code, and then I've found this problem: ```d class MyClass { void member1(); alias mem = member1; } static foreach(mem; __traits(derivedMembers, MyClass)) { pragma(msg, __traits(getMember, MyClass, mem).stringof); //member1 printed twice } ``` This way, I can't dynamically generate code where I have aliases. Related Issue? https://issues.dlang.org/show_bug.cgi?id=19029
Comment #1 by msnmancini — 2023-11-04T13:41:55Z
With help from Paul and Steven, this is the best I could find right now for alias checking: ```d //Checks if the symbol got has the same alias name //And if it points to a member bool isAliasMember(T, string member)() { return __traits(identifier, __traits(getMember, T, member)) == member && __traits(isSame, T, __traits(parent, __traits(getMember, T, member))); } ```
Comment #2 by robert.schadek — 2024-12-07T13:42:59Z
THIS ISSUE HAS BEEN MOVED TO GITHUB https://github.com/dlang/dmd/issues/17467 DO NOT COMMENT HERE ANYMORE, NOBODY WILL SEE IT, THIS ISSUE HAS BEEN MOVED TO GITHUB