Skip to content

Commit

Permalink
Merge pull request #4747 from MartinNowak/fix15907
Browse files Browse the repository at this point in the history
supplemental change for Issue 15907 fix
  • Loading branch information
WalterBright committed Aug 29, 2016
2 parents 01eb06b + ac3db64 commit d10780f
Show file tree
Hide file tree
Showing 4 changed files with 38 additions and 5 deletions.
2 changes: 1 addition & 1 deletion posix.mak
Expand Up @@ -210,7 +210,7 @@ EXTRA_MODULES_INTERNAL := $(addprefix \
gammafunction errorfunction) $(addprefix std/internal/, \
cstring processinit unicode_tables scopebuffer\
unicode_comp unicode_decomp unicode_grapheme unicode_norm) \
$(addprefix std/internal/test/, dummyrange) \
$(addprefix std/internal/test/, dummyrange uda) \
$(addprefix std/experimental/ndslice/, internal) \
$(addprefix std/algorithm/, internal)

Expand Down
10 changes: 10 additions & 0 deletions std/internal/test/uda.d
Expand Up @@ -14,3 +14,13 @@ struct HasPrivateMembers
@Attr private int c;
private int d;
}

// If getSymbolsByUDA is mixed into the same scope it also returns private members
unittest
{
import std.traits : getSymbolsByUDA, hasUDA;
mixin getSymbolsByUDA!(HasPrivateMembers, Attr) symbols;
static assert(symbols.getSymbolsByUDA.length == 2);
static assert(hasUDA!(symbols.getSymbolsByUDA[0], Attr));
static assert(hasUDA!(symbols.getSymbolsByUDA[1], Attr));
}
29 changes: 26 additions & 3 deletions std/traits.d
Expand Up @@ -6798,14 +6798,37 @@ unittest
static assert(getSymbolsByUDA!(C, UDA)[1].stringof == "d");
}

/// mixin getSymbolsByUDA to also find private members
unittest
{
import std.traits;
enum UDA;
struct S
{
@UDA int visible;
@UDA private int invisible;
}
// mixin the template instantiation, using a name to avoid namespace pollution
mixin getSymbolsByUDA!(S, UDA) symbols;
// as the template is instantiated in the current scope, it can see private members
// mixin templates don't perform eponymous expansion, so an additional `.getSymbolsByUDA` is needed
static assert(symbols.getSymbolsByUDA.length == 2);
}

// #15335: getSymbolsByUDA fails if type has private members
unittest
{
// HasPrivateMembers has, well, private members, one of which has a UDA.
// HasPrivateMembers has private members, but only the ones visible from std.traits are returned
import std.internal.test.uda;
static assert(getSymbolsByUDA!(HasPrivateMembers, Attr).length == 2);
// whether allMembers returns private members, see dmd fix for Issue 15907
static if (__traits(allMembers, HasPrivateMembers).length == 2)
static assert(getSymbolsByUDA!(HasPrivateMembers, Attr).length == 1);
else
{
static assert(getSymbolsByUDA!(HasPrivateMembers, Attr).length == 2);
static assert(hasUDA!(getSymbolsByUDA!(HasPrivateMembers, Attr)[1], Attr));
}
static assert(hasUDA!(getSymbolsByUDA!(HasPrivateMembers, Attr)[0], Attr));
static assert(hasUDA!(getSymbolsByUDA!(HasPrivateMembers, Attr)[1], Attr));
}

/**
Expand Down
2 changes: 1 addition & 1 deletion win32.mak
Expand Up @@ -238,7 +238,7 @@ SRC_STD_C_FREEBSD= std\c\freebsd\socket.d
SRC_STD_INTERNAL= std\internal\cstring.d std\internal\processinit.d \
std\internal\unicode_tables.d std\internal\unicode_comp.d std\internal\unicode_decomp.d \
std\internal\unicode_grapheme.d std\internal\unicode_norm.d std\internal\scopebuffer.d \
std\internal\test\dummyrange.d
std\internal\test\dummyrange.d std\internal\test\uda.d

SRC_STD_INTERNAL_DIGEST= std\internal\digest\sha_SSSE3.d

Expand Down

0 comments on commit d10780f

Please sign in to comment.