D issues are now tracked on GitHub. This Bugzilla instance remains as a read-only archive.
Issue 4371 - segfault(template.c) template tuple in is() expression
Summary: segfault(template.c) template tuple in is() expression
Status: RESOLVED FIXED
Alias: None
Product: D
Classification: Unclassified
Component: dmd (show other issues)
Version: D2
Hardware: Other All
: P2 normal
Assignee: No Owner
URL:
Keywords: ice-on-valid-code, patch
Depends on:
Blocks:
 
Reported: 2010-06-22 21:36 UTC by Ellery Newcomer
Modified: 2012-01-28 12:44 UTC (History)
2 users (show)

See Also:


Attachments

Note You need to log in before you can comment on or make changes to this issue.
Description Ellery Newcomer 2010-06-22 21:36:24 UTC
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.
Comment 1 Don 2010-11-26 00:44:26 UTC
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);
Comment 2 Don 2010-11-26 00:46:05 UTC
And the code was valid.
Comment 3 Don 2010-11-26 12:35:50 UTC
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.