Skip to content

Commit

Permalink
Merge pull request #828 from 9rnsr/fix7751
Browse files Browse the repository at this point in the history
Issue 7751 - [ICE] From auto and forward reference
  • Loading branch information
WalterBright committed Mar 29, 2012
2 parents 7815d74 + 48d25a5 commit cd7d2fc
Show file tree
Hide file tree
Showing 2 changed files with 56 additions and 27 deletions.
66 changes: 39 additions & 27 deletions src/cast.c
Expand Up @@ -1572,15 +1572,18 @@ Expression *Expression::inferType(Type *t, int flag, TemplateParameters *tparams

Expression *ArrayLiteralExp::inferType(Type *t, int flag, TemplateParameters *tparams)
{
t = t->toBasetype();
if (t->ty == Tarray || t->ty == Tsarray)
if (t)
{
Type *tn = t->nextOf();
for (size_t i = 0; i < elements->dim; i++)
{ Expression *e = (*elements)[i];
if (e)
{ e = e->inferType(tn, flag, tparams);
(*elements)[i] = e;
t = t->toBasetype();
if (t->ty == Tarray || t->ty == Tsarray)
{
Type *tn = t->nextOf();
for (size_t i = 0; i < elements->dim; i++)
{ Expression *e = (*elements)[i];
if (e)
{ e = e->inferType(tn, flag, tparams);
(*elements)[i] = e;
}
}
}
}
Expand All @@ -1589,23 +1592,26 @@ Expression *ArrayLiteralExp::inferType(Type *t, int flag, TemplateParameters *tp

Expression *AssocArrayLiteralExp::inferType(Type *t, int flag, TemplateParameters *tparams)
{
t = t->toBasetype();
if (t->ty == Taarray)
{ TypeAArray *taa = (TypeAArray *)t;
Type *ti = taa->index;
Type *tv = taa->nextOf();
for (size_t i = 0; i < keys->dim; i++)
{ Expression *e = (*keys)[i];
if (e)
{ e = e->inferType(ti, flag, tparams);
(*keys)[i] = e;
if (t)
{
t = t->toBasetype();
if (t->ty == Taarray)
{ TypeAArray *taa = (TypeAArray *)t;
Type *ti = taa->index;
Type *tv = taa->nextOf();
for (size_t i = 0; i < keys->dim; i++)
{ Expression *e = (*keys)[i];
if (e)
{ e = e->inferType(ti, flag, tparams);
(*keys)[i] = e;
}
}
}
for (size_t i = 0; i < values->dim; i++)
{ Expression *e = (*values)[i];
if (e)
{ e = e->inferType(tv, flag, tparams);
(*values)[i] = e;
for (size_t i = 0; i < values->dim; i++)
{ Expression *e = (*values)[i];
if (e)
{ e = e->inferType(tv, flag, tparams);
(*values)[i] = e;
}
}
}
}
Expand All @@ -1614,6 +1620,9 @@ Expression *AssocArrayLiteralExp::inferType(Type *t, int flag, TemplateParameter

Expression *FuncExp::inferType(Type *to, int flag, TemplateParameters *tparams)
{
if (!to)
return this;

//printf("FuncExp::interType('%s'), to=%s\n", type?type->toChars():"null", to->toChars());

if (!type) // semantic is not yet done
Expand Down Expand Up @@ -1714,9 +1723,12 @@ Expression *FuncExp::inferType(Type *to, int flag, TemplateParameters *tparams)

Expression *CondExp::inferType(Type *t, int flag, TemplateParameters *tparams)
{
t = t->toBasetype();
e1 = e1->inferType(t, flag, tparams);
e2 = e2->inferType(t, flag, tparams);
if (t)
{
t = t->toBasetype();
e1 = e1->inferType(t, flag, tparams);
e2 = e2->inferType(t, flag, tparams);
}
return this;
}

Expand Down
17 changes: 17 additions & 0 deletions test/fail_compilation/fail7751.d
@@ -0,0 +1,17 @@
class Foo(T)
{
T x;
Foo y;
}
auto foo(T)(T x, Foo!T y=null)
{
return new Foo!T(x, y);
}
void bar(U)(U foo, U[] spam=[])
{
spam ~= [];
}
void main()
{
bar(foo(0));
}

0 comments on commit cd7d2fc

Please sign in to comment.