template Seq(T...) { alias T Seq; }
struct S{
int s;
alias Seq!s _;
alias _ this;
}
import std.stdio;
void main(){ writeln(S.init); }
Crashes DMD 2.059 with:
dmd: mtype.c:1279: Type* Type::aliasthisOf(): Assertion `d->type' failed.
Comment #1 by maximzms — 2013-02-05T08:00:07Z
Crashes both DMD 2.061 and Git head with:
--------------------
dmd: aliasthis.c:100: virtual void AliasThis::semantic(Scope*): Assertion `t' failed.
--------------------
Comment #2 by hsteoh — 2014-07-17T18:56:27Z
Wow. This *still* doesn't work on git HEAD: dmd now segfaults.
Comment #3 by hsteoh — 2014-07-17T19:00:14Z
Stack trace:
#0 0x0000000000410199 in TypeStruct::implicitConvTo(Type*) ()
#1 0x00000000004c8213 in IsExp::semantic(Scope*) ()
#2 0x00000000004de990 in AndAndExp::semantic(Scope*) ()
#3 0x00000000004de924 in AndAndExp::semantic(Scope*) ()
#4 0x00000000004de924 in AndAndExp::semantic(Scope*) ()
#5 0x00000000004de924 in AndAndExp::semantic(Scope*) ()
#6 0x00000000004b4769 in StaticIfCondition::include(Scope*, ScopeDsymbol*) ()
#7 0x000000000043d637 in ConditionalStatement::flatten(Scope*) ()
#8 0x00000000004437d1 in CompoundStatement::semantic(Scope*) ()
#9 0x00000000004ede13 in FuncDeclaration::semantic3(Scope*) ()
#10 0x00000000004504c4 in TemplateInstance::semantic3(Scope*) ()
#11 0x0000000000454d83 in TemplateInstance::trySemantic3(Scope*) ()
#12 0x000000000045c2e3 in TemplateInstance::semantic(Scope*, Array<Expression*>*) [clone .part.63] ()
#13 0x000000000045c87f in functionResolve(Match*, Dsymbol*, Loc, Scope*, Array<RootObject*>*, Type*, Array<Expression*>*) ()
#14 0x00000000004ec05e in resolveFuncCall(Loc, Scope*, Dsymbol*, Array<RootObject*>*, Type*, Array<Expression*>*, int) ()
#15 0x00000000004d3c33 in CallExp::semantic(Scope*) [clone .part.134] ()
#16 0x000000000043fd9b in ExpStatement::semantic(Scope*) ()
#17 0x0000000000443b6a in CompoundStatement::semantic(Scope*) ()
#18 0x00000000004ede13 in FuncDeclaration::semantic3(Scope*) ()
#19 0x0000000000407a50 in Module::semantic3() ()
#20 0x000000000040526c in tryMain(unsigned long, char const**) ()
#21 0x00007ffff7015b45 in __libc_start_main (main=0x402490 <main>, argc=2, argv=0x7fffffffeb68,
init=<optimized out>, fini=<optimized out>, rtld_fini=<optimized out>, stack_end=0x7fffffffeb58)
at libc-start.c:287
#22 0x00000000004029c5 in _start ()
Comment #4 by hsteoh — 2014-07-17T19:14:40Z
Cause of segfault: aliasthisOf() returned NULL to implicitConvTo().
Comment #5 by hsteoh — 2014-07-17T20:03:30Z
And the reason is because aliasthisOf() does not expect a TypeTuple; it expects a variable declaration, a function, an enum, or a template. Normally, TypeTuples cannot appear in an alias this due to the current grammar, but there is a loophole where they can be masked by another layer of alias, as in the code given here, so it leads into this unhandled case.
Here's another example of a crash at the same location reduced by dustmite:
struct Tuple9709(T...)
{
alias T expand;
alias expand this;
}
auto data = RTInfoImpl2!(Tuple9709!1);
template RTInfoImpl2(T)
{
static if (is(T D == U))
immutable(RTInfoData) RTInfoImpl2 ;
}
[this is also triggered by some RTInfo compiled with the dmd test suite.]
There are some code locations that check the pointer returned by aliasthisOf(), some do not. Should these be added in the places where the checks are missing?