Issue 24480 - getSymbolsByUDA ignores template functions
Summary: getSymbolsByUDA ignores template functions
Status: NEW
Alias: None
Product: D
Classification: Unclassified
Component: phobos (show other issues)
Version: D2
Hardware: All Mac OS X
: P1 normal
Assignee: No Owner
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2024-04-03 23:35 UTC by johanengelen
Modified: 2024-12-01 16:42 UTC (History)
1 user (show)

See Also:


Attachments

Note You need to log in before you can comment on or make changes to this issue.
Description johanengelen 2024-04-03 23:35:14 UTC
Testcase:
```
struct SomeUDA {}

struct S {
    @SomeUDA S opBinary(string op: "-")(S rhs) const pure nothrow @nogc {
        return rhs;
    }
    S opBinary(string op: "*")(S dur) const pure nothrow @nogc {
        return dur;
    }
}

import std.traits;
pragma(msg, getSymbolsByUDA!(S, SomeUDA));
```

This prints "()", i.e. does not return the template function (https://d.godbolt.org/z/Th86qvMGM).

Seems to be fixed by adding `true` on this line https://github.com/dlang/phobos/blob/77adcadf7961dbe1177aa79be381311404a81d46/std/traits.d#L9009 (similar to the `if` condition three lines above it). However, then this slightly modified testcase still fails:

```
struct S {
    S opBinary(string op: "-")(S rhs) const pure nothrow @nogc {
        return rhs;
    }
    @SomeUDA S opBinary(string op: "*")(S dur) const pure nothrow @nogc {
        return dur;
    }
}
```
Comment 1 Jonathan M Davis 2024-04-05 22:27:01 UTC
Yeah, __traits(getOverloads, ...) won't give you templated overloads unless you tell it to - and in the general case, it really isn't going to work well to get attributes from a templated function because of attribute inference. However, for UDAs, they should be there regardless.
Comment 2 dlangBugzillaToGithub 2024-12-01 16:42:23 UTC
THIS ISSUE HAS BEEN MOVED TO GITHUB

https://github.com/dlang/phobos/issues/10546

DO NOT COMMENT HERE ANYMORE, NOBODY WILL SEE IT, THIS ISSUE HAS BEEN MOVED TO GITHUB