The code: struct s(T ...){ } alias s!("hi!") t; static if(is(t U == s!(U))){ } void main(){ } The fireworks: Segmentation fault (core dumped) on compile.
There are two issues: (1) deduceType() can return a tuple. This causes the segfault, because it isn't a type. Fixing that stops the crash, but the code still doesn't work, because... (2) Same as bug 5164: it shouldn't try to add the symbol twice. Exactly the same fix works here. PATCH: expression.c, line 5185, IsExp::semantic(). ---------- Lyes: if (id) { - Dsymbol *s = new AliasDeclaration(loc, id, tded); + Dsymbol *s; + if (isTuple(tded)) + s = new TupleDeclaration(loc, id, &(isTuple(tded)->objects)); + else + s = new AliasDeclaration(loc, id, tded); s->semantic(sc); - if (!sc->insert(s)) - error("declaration %s is already defined", s->toChars()); if (sc->sd) s->addMember(sc, sc->sd, 1); + else if (!sc->insert(s)) + error("declaration %s is already defined", s->toChars()); } //printf("Lyes\n"); return new IntegerExp(loc, 1, Type::tbool); Lno: //printf("Lno\n"); return new IntegerExp(loc, 0, Type::tbool);
And the code was valid.
There's something wrong with the patch. This part breaks Phobos unit tests: - if (!sc->insert(s)) - error("declaration %s is already defined", s->toChars()); if (sc->sd) s->addMember(sc, sc->sd, 1); + else if (!sc->insert(s)) + error("declaration %s is already defined", s->toChars()); Changing the first of those lines to: if (!isTuple(tded) && !sc->insert(s)) error("declaration %s is already defined", s->toChars()); allows the test code to compile. But I don't really understand why it should be necessary. Possibly it's another bug which is being triggered.
Commit pushed to master at https://github.com/D-Programming-Language/dmd https://github.com/D-Programming-Language/dmd/commit/a48c43c9e3b7dc57092c1a72c1e019c46178f11b Commit pushed to dmd-1.x at https://github.com/D-Programming-Language/dmd https://github.com/D-Programming-Language/dmd/commit/999ef822efdca31c6983ea89805b178526c53c3d