Skip to content

Fix Issue 23977 - [REG2.102] cannot use getSymbolsByUDA on template struct with alias member #8775

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: stable
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 17 additions & 2 deletions std/traits.d
Original file line number Diff line number Diff line change
Expand Up @@ -8910,9 +8910,9 @@ template getSymbolsByUDA(alias symbol, alias attribute)
static assert(is(getSymbolsByUDA!(X, X) == AliasSeq!()));
}

// https://issues.dlang.org/show_bug.cgi?id=23776
@safe pure nothrow @nogc unittest
{
// https://issues.dlang.org/show_bug.cgi?id=23776
struct T
{
struct Tag {}
Expand All @@ -8932,6 +8932,18 @@ template getSymbolsByUDA(alias symbol, alias attribute)
}
alias xcomponents = getSymbolsByUDA!(X, X.Tag);
static assert(xcomponents.length > 0);

// https://issues.dlang.org/show_bug.cgi?id=23977
struct S(string str)
{
alias strstr = str;

int i;
}

static struct A {}

assert((getSymbolsByUDA!(S!("a"), A)).length == 0);
}

// getSymbolsByUDA produces wrong result if one of the symbols having the UDA is a function
Expand Down Expand Up @@ -8991,7 +9003,10 @@ private template getSymbolsByUDAImpl(alias symbol, alias attribute, names...)

// Filtering not compiled members such as alias of basic types.
static if (isAliasSeq!member ||
(isType!member && !isAggregateType!member && !is(member == enum)))
// exclude basic types and derived types
(isType!member && !isAggregateType!member && !is(member == enum)) ||
// exclude aliases to expressions such as string literals
__traits(compiles, { auto ex = member; }))
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is probably not the best idea to test if member is an expression. I took inspiration from the isExpressions template. I did not want to use it to not cause avoidable template bloat.

{
alias getSymbolsByUDAImpl = tail;
}
Expand Down
Loading