mirror of
https://github.com/dlang/phobos.git
synced 2025-05-05 09:30:49 +03:00
Merge pull request #4164 from Ukalnins/issue_15874
Fix Issue 15874 - getSymbolsByUDA fails if struct has no UDAs
This commit is contained in:
commit
cf4f09f12e
1 changed files with 10 additions and 2 deletions
12
std/traits.d
12
std/traits.d
|
@ -6723,8 +6723,8 @@ template getSymbolsByUDA(alias symbol, alias attribute) {
|
|||
// translate a list of strings into symbols. mixing in the entire alias
|
||||
// avoids trying to access the symbol, which could cause a privacy violation
|
||||
template toSymbols(names...) {
|
||||
static if (names.length == 1)
|
||||
mixin("alias toSymbols = AliasSeq!(symbol.%s);".format(names[0]));
|
||||
static if (names.length == 0)
|
||||
alias toSymbols = AliasSeq!();
|
||||
else
|
||||
mixin("alias toSymbols = AliasSeq!(symbol.%s, toSymbols!(names[1..$]));"
|
||||
.format(names[0]));
|
||||
|
@ -6796,6 +6796,14 @@ unittest
|
|||
static assert(getSymbolsByUDA!(C, UDA).length == 2);
|
||||
static assert(getSymbolsByUDA!(C, UDA)[0].stringof == "C");
|
||||
static assert(getSymbolsByUDA!(C, UDA)[1].stringof == "d");
|
||||
|
||||
static struct D
|
||||
{
|
||||
int x;
|
||||
}
|
||||
|
||||
//Finds nothing if there is no member with specific UDA
|
||||
static assert(getSymbolsByUDA!(D,UDA).length == 0);
|
||||
}
|
||||
|
||||
// #15335: getSymbolsByUDA fails if type has private members
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue