Skip to content

Commit

Permalink
Merge pull request #4103 from 9rnsr/fix13668
Browse files Browse the repository at this point in the history
Issue 13668 - [ICE] unable to compile __traits(allMembers...)
  • Loading branch information
WalterBright committed Nov 2, 2014
2 parents 22cefce + 62cc5c8 commit a62084e
Show file tree
Hide file tree
Showing 2 changed files with 44 additions and 1 deletion.
7 changes: 6 additions & 1 deletion src/traits.c
Expand Up @@ -835,7 +835,8 @@ Expression *semanticTraits(TraitsExp *e, Scope *sc)
/* Skip if already present in idents[]
*/
for (size_t j = 0; j < idents->dim; j++)
{ Identifier *id = (*idents)[j];
{
Identifier *id = (*idents)[j];
if (id == sm->ident)
return 0;
#ifdef DEBUG
Expand Down Expand Up @@ -865,13 +866,17 @@ Expression *semanticTraits(TraitsExp *e, Scope *sc)
ClassDeclaration *cd = sds->isClassDeclaration();
if (cd && e->ident == Id::allMembers)
{
if (cd->scope)
cd->semantic(NULL); // Bugzilla 13668: Try to resolve forward reference

struct PushBaseMembers
{
static void dg(ClassDeclaration *cd, Identifiers *idents)
{
for (size_t i = 0; i < cd->baseclasses->dim; i++)
{
ClassDeclaration *cb = (*cd->baseclasses)[i]->base;
assert(cb);
ScopeDsymbol::foreach(NULL, cb->members, &PushIdentsDg::dg, idents);
if (cb->baseclasses->dim)
dg(cb, idents);
Expand Down
38 changes: 38 additions & 0 deletions test/compilable/test13668.d
@@ -0,0 +1,38 @@
// REQUIRED_ARGS: -o-
// PERMUTE_ARGS:
/*
TEST_OUTPUT:
---
tuple("id", "toString", "toHash", "opCmp", "opEquals", "Monitor", "factory")
genProps
---
*/

class User : Entity!User
{
int id;
}

class Entity(T)
{
pragma(msg, generateProperties!T);
/* Compiler runs pragma(msg) in semantic() phase, but it does not insert any members
* in this class. Therefore getting __traits(allMembers, User) while evaluating
* generateProperties!User should work.
*/
}

template generateProperties(alias To)
{
string getProperties(alias Ta)()
{
string toRet = "genProps";

// This line is bad
pragma(msg, __traits(allMembers, Ta));

return toRet;
}

enum generateProperties = getProperties!(To);
}

0 comments on commit a62084e

Please sign in to comment.