Bug 23855 – traits getOverloads returns overload when one of the symbols is a templatized function

Status
NEW
Severity
normal
Priority
P1
Component
dmd
Product
D
Version
D2
Platform
x86_64
OS
Linux
Creation time
2023-04-24T07:13:24Z
Last change time
2024-12-13T19:28:24Z
Keywords
industry
Assigned to
No Owner
Creator
FeepingCreature
Moved to GitHub: dmd#20263 →

Comments

Comment #0 by default_357-line — 2023-04-24T07:13:24Z
That's right, it's the revenge of #16206 ! ``` void test()() { } void test(int) { } void main() { alias thisModule = __traits(parent, main); alias overloads = __traits(getOverloads, thisModule, "test"); pragma(msg, overloads.length); // returns 1 static foreach (member; overloads) { alias udas = __traits(getAttributes, member); } } ``` Leads to ``` Deprecation: `__traits(getAttributes)` may only be used for individual functions, not overload sets such as: `test` the result of `__traits(getOverloads)` may be used to select the desired function to extract attributes from ``` Ie. despite two symbols existing, __traits(getOverloads) returns the combined overload set. And for once, it's independent of order too.
Comment #1 by default_357-line — 2023-04-24T07:23:55Z
Note: this is not a matter of the "includeTemplates" argument to `getOverloads`. If I set that to `true`, I still cannot actually get the attributes of the member symbols - though I get a tuple of two in that case. The weird thing is that `pragma(msg, member.mangleof)` suggests that `getOverloads selects the right functions, but I still get the deprecation warning on both of them. Maybe it's the deprecation that's confused?
Comment #2 by default_357-line — 2023-04-24T07:40:53Z
Far as I can tell, `__traits(getOverloads)` just doesn't get rid of the overloadness of the template or function correctly. `td.funcroot` is set, `fd.overnext` is set, but `__traits(getOverloads)` only zeroes `td.overnext`.
Comment #3 by default_357-line — 2023-04-24T08:27:38Z
Okay, I can't work this out on my own, but it's *something* about `static foreach`: `alias udas = __traits(getAttributes, overloads[0]);` works. Somehow the loop variable in `static foreach` ends up in the original module symbol, `overnext` included: it's supposed to be a `FuncAliasDeclaration` from `getOverloads`, but even though it creates the tuple right, somewhere in the `static foreach` code, DMD gets rid of it again.
Comment #4 by nick — 2024-07-29T10:40:15Z
> Deprecation: `__traits(getAttributes)` may only be used for individual functions, not overload sets such as: `test` I get no deprecation message with recent dmd. > Note: this is not a matter of the "includeTemplates" argument to `getOverloads`. If I set that to `true`, I still cannot actually get the attributes of the member symbols This works: @1 void test()() { } @2 void test(int) { } void main() { alias thisModule = __traits(parent, main); alias overloads = __traits(getOverloads, thisModule, "test", true); static foreach (member; overloads) { pragma(msg, __traits(getAttributes, member)); } }
Comment #5 by robert.schadek — 2024-12-13T19:28:24Z
THIS ISSUE HAS BEEN MOVED TO GITHUB https://github.com/dlang/dmd/issues/20263 DO NOT COMMENT HERE ANYMORE, NOBODY WILL SEE IT, THIS ISSUE HAS BEEN MOVED TO GITHUB