Skip to content

Commit

Permalink
merge D2 pull #690
Browse files Browse the repository at this point in the history
  • Loading branch information
9rnsr committed Jul 21, 2012
1 parent d7a1b1c commit 55bedf4
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 1 deletion.
33 changes: 32 additions & 1 deletion src/init.c
Expand Up @@ -470,8 +470,33 @@ Initializer *ArrayInitializer::semantic(Scope *sc, Type *t, NeedInterpret needIn
}

Initializer *val = value[i];
ExpInitializer *ei = val->isExpInitializer();
if (ei && !idx)
ei->expandTuples = 1;
val = val->semantic(sc, t->nextOf(), needInterpret);
value[i] = val;

ei = val->isExpInitializer();
// found a tuple, expand it
if (ei && ei->exp->op == TOKtuple)
{
TupleExp *te = (TupleExp *)ei->exp;
index.remove(i);
value.remove(i);

for (size_t j = 0; j < te->exps->dim; ++j)
{
Expression *e = (*te->exps)[j];
index.insert(i + j, (Expression *)NULL);
value.insert(i + j, new ExpInitializer(e->loc, e));
}
i--;
continue;
}
else
{
value[i] = val;
}

length++;
if (length == 0)
{ error(loc, "array dimension overflow");
Expand Down Expand Up @@ -696,6 +721,7 @@ ExpInitializer::ExpInitializer(Loc loc, Expression *exp)
: Initializer(loc)
{
this->exp = exp;
this->expandTuples = 0;
}

Initializer *ExpInitializer::syntaxCopy()
Expand All @@ -722,6 +748,11 @@ Initializer *ExpInitializer::semantic(Scope *sc, Type *t, NeedInterpret needInte
exp->error("initializer must be an expression, not '%s'", exp->toChars());
Type *tb = t->toBasetype();

if (exp->op == TOKtuple &&
expandTuples &&
!exp->implicitConvTo(t))
return new ExpInitializer(loc, exp);

/* Look for case of initializing a static array with a too-short
* string literal, such as:
* char[5] foo = "abc";
Expand Down
1 change: 1 addition & 0 deletions src/init.h
Expand Up @@ -113,6 +113,7 @@ struct ArrayInitializer : Initializer
struct ExpInitializer : Initializer
{
Expression *exp;
int expandTuples;

ExpInitializer(Loc loc, Expression *exp);
Initializer *syntaxCopy();
Expand Down

0 comments on commit 55bedf4

Please sign in to comment.