Skip to content

Commit

Permalink
fix Issue 14986 - Assertion failed: (id->dyncast() == DYNCAST_DSYMBOL)
Browse files Browse the repository at this point in the history
  • Loading branch information
9rnsr committed Aug 31, 2015
1 parent ce8e6d1 commit 0f50f12
Show file tree
Hide file tree
Showing 2 changed files with 101 additions and 18 deletions.
92 changes: 74 additions & 18 deletions src/mtype.c
Expand Up @@ -6885,16 +6885,32 @@ Expression *TypeIdentifier::toExpression()
for (size_t i = 0; i < idents.dim; i++)
{
RootObject *id = idents[i];
if (id->dyncast() == DYNCAST_IDENTIFIER)
{
e = new DotIdExp(loc, e, (Identifier *)id);
}
else
switch (id->dyncast())
{
assert(id->dyncast() == DYNCAST_DSYMBOL);
TemplateInstance *ti = ((Dsymbol *)id)->isTemplateInstance();
assert(ti);
e = new DotTemplateInstanceExp(loc, e, ti->name, ti->tiargs);
case DYNCAST_IDENTIFIER:
{
e = new DotIdExp(loc, e, (Identifier *)id);
break;
}
case DYNCAST_DSYMBOL:
{
TemplateInstance *ti = ((Dsymbol *)id)->isTemplateInstance();
assert(ti);
e = new DotTemplateInstanceExp(loc, e, ti->name, ti->tiargs);
break;
}
case DYNCAST_TYPE:
{
e = new ArrayExp(loc, e, new TypeExp(loc, (Type *)id));
break;
}
case DYNCAST_EXPRESSION:
{
e = new ArrayExp(loc, e, (Expression *)id);
break;
}
default:
assert(0);
}
}

Expand Down Expand Up @@ -7009,16 +7025,32 @@ Expression *TypeInstance::toExpression()
for (size_t i = 0; i < idents.dim; i++)
{
RootObject *id = idents[i];
if (id->dyncast() == DYNCAST_IDENTIFIER)
switch (id->dyncast())
{
e = new DotIdExp(loc, e, (Identifier *)id);
}
else
{
assert(id->dyncast() == DYNCAST_DSYMBOL);
TemplateInstance *ti = ((Dsymbol *)id)->isTemplateInstance();
assert(ti);
e = new DotTemplateInstanceExp(loc, e, ti->name, ti->tiargs);
case DYNCAST_IDENTIFIER:
{
e = new DotIdExp(loc, e, (Identifier *)id);
break;
}
case DYNCAST_DSYMBOL:
{
TemplateInstance *ti = ((Dsymbol *)id)->isTemplateInstance();
assert(ti);
e = new DotTemplateInstanceExp(loc, e, ti->name, ti->tiargs);
break;
}
case DYNCAST_TYPE:
{
e = new ArrayExp(loc, e, new TypeExp(loc, (Type *)id));
break;
}
case DYNCAST_EXPRESSION:
{
e = new ArrayExp(loc, e, (Expression *)id);
break;
}
default:
assert(0);
}
}

Expand Down Expand Up @@ -7138,14 +7170,26 @@ void TypeTypeof::resolve(Loc loc, Scope *sc, Expression **pe, Type **pt, Dsymbol
switch (id->dyncast())
{
case DYNCAST_IDENTIFIER:
{
e = new DotIdExp(loc, e, (Identifier *)id);
break;
}
case DYNCAST_DSYMBOL:
{
TemplateInstance *ti = ((Dsymbol *)id)->isTemplateInstance();
e = new DotExp(loc, e, new ScopeExp(loc, ti));
break;
}
case DYNCAST_TYPE:
{
e = new ArrayExp(loc, e, new TypeExp(loc, (Type *)id));
break;
}
case DYNCAST_EXPRESSION:
{
e = new ArrayExp(loc, e, (Expression *)id);
break;
}
default:
assert(0);
}
Expand Down Expand Up @@ -7264,14 +7308,26 @@ void TypeReturn::resolve(Loc loc, Scope *sc, Expression **pe, Type **pt, Dsymbol
switch (id->dyncast())
{
case DYNCAST_IDENTIFIER:
{
e = new DotIdExp(loc, e, (Identifier *)id);
break;
}
case DYNCAST_DSYMBOL:
{
TemplateInstance *ti = ((Dsymbol *)id)->isTemplateInstance();
e = new DotExp(loc, e, new ScopeExp(loc, ti));
break;
}
case DYNCAST_TYPE:
{
e = new ArrayExp(loc, e, new TypeExp(loc, (Type *)id));
break;
}
case DYNCAST_EXPRESSION:
{
e = new ArrayExp(loc, e, (Expression *)id);
break;
}
default:
assert(0);
}
Expand Down
27 changes: 27 additions & 0 deletions test/compilable/b1215.d
Expand Up @@ -117,3 +117,30 @@ void test14911()
S* buf2 = (new S[2]).ptr; // OK
S* buf3 = new S[2].ptr; // OK <- broken
}

/***************************************************/
// 14986

alias Id14986(alias a) = a;

struct Foo14986
{
int tsize;
}
struct Bar14986
{
enum Foo14986[] arr = [Foo14986()];
}

Bar14986 test14986()
{
Foo14986[] types;
auto a1 = new void[types[0].tsize]; // TypeIdentifier::toExpression
auto a2 = new void[Id14986!types[0].tsize]; // TypeInstance::toExpression

Bar14986 bar;
auto a3 = Id14986!(typeof(bar).arr[0].tsize); // TypeTypeof::resolve
auto a4 = Id14986!(typeof(return).arr[0].tsize); // TypeReturn::resolve

return Bar14986();
}

0 comments on commit 0f50f12

Please sign in to comment.