Skip to content

Commit

Permalink
Fix getSymbolsByUDA by replacing broad __traits(compiles) with a more…
Browse files Browse the repository at this point in the history
… focused condition
  • Loading branch information
RazvanN7 authored and Geod24 committed Nov 28, 2022
1 parent f710b08 commit e305dc9
Showing 1 changed file with 11 additions and 3 deletions.
14 changes: 11 additions & 3 deletions std/traits.d
Original file line number Diff line number Diff line change
Expand Up @@ -8847,6 +8847,14 @@ version (StdUnittest)
static assert(__traits(compiles, getSymbolsByUDA!(mixin(__MODULE__), "Issue20054")));
}

private template isAliasSeq(Args...)
{
static if (Args.length != 1)
enum isAliasSeq = true;
else
enum isAliasSeq = false;
}

private template getSymbolsByUDAImpl(alias symbol, alias attribute, names...)
{
import std.meta : Alias, AliasSeq, Filter;
Expand All @@ -8868,12 +8876,12 @@ private template getSymbolsByUDAImpl(alias symbol, alias attribute, names...)
alias member = __traits(getMember, symbol, names[0]);

// Filtering not compiled members such as alias of basic types.
static if (!__traits(compiles, hasUDA!(member, attribute)))
static if (isAliasSeq!member || isType!member)
{
alias getSymbolsByUDAImpl = tail;
}
// Get overloads for functions, in case different overloads have different sets of UDAs.
else static if (isFunction!member)
// If a symbol is overloaded, get UDAs for each overload (including templated overlaods).
else static if (__traits(getOverloads, symbol, names[0], true).length > 0)
{
enum hasSpecificUDA(alias member) = hasUDA!(member, attribute);
alias overloadsWithUDA = Filter!(hasSpecificUDA, __traits(getOverloads, symbol, names[0]));
Expand Down

0 comments on commit e305dc9

Please sign in to comment.