Skip to content
Merged
Show file tree
Hide file tree
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
1 change: 1 addition & 0 deletions src/idgen.c
Original file line number Diff line number Diff line change
Expand Up @@ -307,6 +307,7 @@ Msgtable msgtable[] =
{ "isAssociativeArray" },
{ "isFinalClass" },
{ "isPOD" },
{ "isNested" },
{ "isFloating" },
{ "isIntegral" },
{ "isScalar" },
Expand Down
28 changes: 28 additions & 0 deletions src/traits.c
Original file line number Diff line number Diff line change
Expand Up @@ -168,6 +168,34 @@ Expression *TraitsExp::semantic(Scope *sc)
}
goto Ltrue;
}
else if (ident == Id::isNested)
{
if (dim != 1)
goto Ldimerror;
Object *o = (*args)[0];
Dsymbol *s = getDsymbol(o);
AggregateDeclaration *a;
FuncDeclaration *f;

if (!s) { }
else if ((a = s->isAggregateDeclaration()) != NULL)
{
if (a->isnested)
goto Ltrue;
else
goto Lfalse;
}
else if ((f = s->isFuncDeclaration()) != NULL)
{
if (f->isNested())
goto Ltrue;
else
goto Lfalse;
}

error("aggregate or function expected instead of '%s'", o->toChars());
goto Lfalse;
}
else if (ident == Id::isAbstractFunction)
{
FuncDeclaration *f;
Expand Down
30 changes: 30 additions & 0 deletions test/runnable/traits.d
Original file line number Diff line number Diff line change
Expand Up @@ -1043,6 +1043,35 @@ void test9552()

/*************************************************************/

void test9136()
{
int x;
struct S1 { void f() { x++; } }
struct U1 { void f() { x++; } }
static struct S2 { }
static struct S3 { S1 s; }
static struct U2 { }
void f1() { x++; }
static void f2() { }

static assert(__traits(isNested, S1));
static assert(__traits(isNested, U1));
static assert(!__traits(isNested, S2));
static assert(!__traits(isNested, S3));
static assert(!__traits(isNested, U2));
static assert(!__traits(compiles, __traits(isNested, int) ));
static assert(!__traits(compiles, __traits(isNested, f1, f2) ));
static assert(__traits(isNested, f1));
static assert(!__traits(isNested, f2));

static class A { static class SC { } class NC { } }
static assert(!__traits(isNested, A));
static assert(!__traits(isNested, A.SC));
static assert(__traits(isNested, A.NC));
}

/********************************************************/

int main()
{
test1();
Expand Down Expand Up @@ -1075,6 +1104,7 @@ int main()
test5978();
test7408();
test9552();
test9136();

writeln("Success");
return 0;
Expand Down