Bug 23500 – std.traits.getUDAs not working properly for overloads

Status
NEW
Severity
blocker
Priority
P1
Component
phobos
Product
D
Version
D2
Platform
x86_64
OS
Linux
Creation time
2022-11-21T14:14:53Z
Last change time
2024-12-01T16:40:47Z
Assigned to
No Owner
Creator
RazvanN
Moved to GitHub: phobos#9851 →

Comments

Comment #0 by razvan.nitu1305 — 2022-11-21T14:14:53Z
import std.traits; @safe void main() { enum attr1; enum attr2; struct A { @attr1 void foo(); @attr2 void foo(int a); } pragma(msg, getUDAs!(A.foo, attr2)); } I would expect this to print (attr2), however, it does not print anything. If I change the example to get attr1 then it works. I expect that for overload sets, getUDAs should iterate through the overloads and report if any of the overloads has the given udas. Right now, it just reports the udas for the first overload it finds. This has been discovered while trying to fix __traits(getAttributes) in the compiler : https://github.com/dlang/dmd/pull/14554
Comment #1 by alphaglosined — 2023-02-16T14:15:08Z
This was rediscovered by a user on Discord. The deprecation message wasn't very good. /usr/include/dmd/phobos/std/traits.d(8514): Deprecation: __traits(getAttributes) may only be used for individual functions, not overload sets such as: __ctor I modified the example here to demonstrate how to change their code: ```d import std.traits; void main() { enum attr1; enum attr2; struct A { @attr1 void foo(); @attr2 void foo(int a); } static foreach(overload; __traits(getOverloads, A, "foo")) { pragma(msg, getUDAs!(overload, attr2)); } } ``` That deprecation message should be improved with more context, although perhaps there are some improvements that could be done more broadly like giving more context (i.e. what triggered that instantiation of getUDAs).
Comment #2 by johanengelen — 2023-06-04T19:35:02Z
Comment #3 by johanengelen — 2023-06-04T19:36:55Z
Failing testcase with templates: ``` module test; import std.traits; @("gigi") void fun() {} @("mimi") void fun(int) {} void fun()(int, ulong) {} void main() { static foreach (t; __traits(getOverloads, test, "fun")) pragma(msg, hasUDA!(t, "gigi")); } ```
Comment #4 by robert.schadek — 2024-12-01T16:40:47Z
THIS ISSUE HAS BEEN MOVED TO GITHUB https://github.com/dlang/phobos/issues/9851 DO NOT COMMENT HERE ANYMORE, NOBODY WILL SEE IT, THIS ISSUE HAS BEEN MOVED TO GITHUB