Skip to content

Commit

Permalink
fix Issue 9017 - __traits(compiles, { enum e = <expression tuple>; })…
Browse files Browse the repository at this point in the history
… is true but code doesn't compile
  • Loading branch information
9rnsr committed Aug 12, 2013
1 parent 62b152b commit 435af31
Show file tree
Hide file tree
Showing 3 changed files with 33 additions and 0 deletions.
3 changes: 3 additions & 0 deletions src/cast.c
Expand Up @@ -1566,6 +1566,9 @@ Expression *AddrExp::castTo(Scope *sc, Type *t)

Expression *TupleExp::castTo(Scope *sc, Type *t)
{
if (type->equals(t))
return this;

TupleExp *e = (TupleExp *)copy();
e->e0 = e0 ? e0->copy() : NULL;
e->exps = (Expressions *)exps->copy();
Expand Down
1 change: 1 addition & 0 deletions src/declaration.c
Expand Up @@ -1126,6 +1126,7 @@ void VarDeclaration::semantic(Scope *sc)
}

VarDeclaration *v = new VarDeclaration(loc, arg->type, id, ti);
v->storage_class |= storage_class;
if (arg->storageClass & STCparameter)
v->storage_class |= arg->storageClass;
//printf("declaring field %s of type %s\n", v->toChars(), v->type->toChars());
Expand Down
29 changes: 29 additions & 0 deletions test/runnable/variadic.d
Expand Up @@ -1514,6 +1514,34 @@ void test7263()
auto spam2 = bars.front7263[1..2];
}

/***************************************/
// 9017

template X9017(Args...)
{
static if(__traits(compiles, { enum e = Args; }))
enum e = Args;
}
alias X9017!0 x9017;
static assert(x9017.e[0] == 0);

void test9017()
{
enum tup1 = TypeTuple!(11, 22);
enum tup2 = TypeTuple!("one", "two");
static assert(tup1 == TypeTuple!(11, 22));
static assert(tup2 == TypeTuple!("one", "two"));
static assert(tup1[0] == 11 && tup1[1] == 22);
static assert(tup2[0] == "one" && tup2[1] == "two");

shared const tup3 = TypeTuple!(10, 3.14);
immutable tup4 = TypeTuple!("a", [1,2]);
static assert(is(typeof(tup3[0]) == shared const int));
static assert(is(typeof(tup3[1]) == shared const double));
static assert(is(typeof(tup4[0]) == immutable string));
static assert(is(typeof(tup4[1]) == immutable int[]));
}

/***************************************/
// 10279

Expand Down Expand Up @@ -1612,6 +1640,7 @@ int main()
test6530();
test7233();
test7263();
test9017();
test10414();

printf("Success\n");
Expand Down

0 comments on commit 435af31

Please sign in to comment.