www.digitalmars.com         C & C++   DMDScript  

digitalmars.D.bugs - [Issue 10431] New: ICE(DMD 2.063) in struct.c:741

reply d-bugmail puremagic.com writes:
http://d.puremagic.com/issues/show_bug.cgi?id=10431

           Summary: ICE(DMD 2.063) in struct.c:741
           Product: D
           Version: D2
          Platform: All
        OS/Version: All
            Status: NEW
          Severity: normal
          Priority: P2
         Component: DMD
        AssignedTo: nobody puremagic.com
        ReportedBy: timon.gehr gmx.ch


--- Comment #0 from timon.gehr gmx.ch 2013-06-20 15:15:39 PDT ---
DMD 2.063:

Compiling the code below:
dmd: struct.c:741: virtual void StructDeclaration::semantic(Scope*): Assertion
`type->ty != Tstruct || ((TypeStruct *)type)->sym == this' failed.

The following code should compile and run:

import std.conv, std.algorithm, std.range;
import std.uni, std.typecons, std.string, std.array;

mixin ADT!q{ ListI: NilI | Cons int ListI };
mixin ADT!q{ Pair(T,S): PP T S };
mixin ADT!q{
 List(T):
 | Nil
 | Cons T List!T
};

mixin ADT!q{ Tree(T): Leaf | Node Tree!T Leaf!T Tree!T };

mixin ADT!q{
 DayOfWeek:
 | Monday
 | Tuesday
 | Wednesday
 | Thursday
 | Friday
 | Saturday
 | Sunday
};

auto list(R)(R r){
    if(r.empty) return Nil!(ElementType!R);
    auto f = r.front;
    r.popFront();
    return Cons(f,list(r));
}

size_t length(T)(List!T l){ return
    l.match!(
        ()=>0,
        (x,xs)=>1+length(xs)
    );
}

void main(){
    import std.stdio;
    writeln(PP(1,2));
    pragma(msg, typeof(PP(1,2)));
    auto l=[1,2,3,4,5].list;
    l.match!(()=>writeln(0),(x,xs)=>writeln(xs));
    writeln(l," ",l.length);
    writeln(Monday);
    writeln(Tuesday);
    writeln(Leaf!int);
    writeln(Cons(1,Nil!int));
}

template Seq(T...){ alias T Seq; }

void white(ref string s){
    while(!s.empty && isWhite(s.front)) s.popFront();
}

string ident(ref string s){
    string r;
    s.white();
    while(isAlpha(s.front)){
        r~=s.front;
        s.popFront();
    }
    return r;
}

string nonwhite(ref string s){
    string r;
    s.white();
    while(!isWhite(s.front)){
        r~=s.front;
        s.popFront();
    }
    return r;
}

void expect(ref string s, dchar c){
    s.white();
    if(s.front != c) throw new Exception("");
    s.popFront();
}

struct Sum{
    string name;
    string[] types;
}

Sum sum(ref string s){
    Sum r;
    r.name = s.ident();
    s.white();
    while(!s.empty && s.front != '|'){
        r.types~=s.nonwhite();
        s.white();
    }
    return r;
}

string create(string s){
    auto name = s.ident;
    string params;
    bool hasparams = false;
    if(s.front=='('){
        hasparams = true;
        s.expect('(');
        while(s.front!=')'){
            params~=s.front;
            s.popFront();
        }
        s.expect(')');
    }
    s.expect(':');
    string r;
    r~="struct "~name;
    if(hasparams) r~="("~params~")";
    r~="{";

    Sum[] sums;

    s.white();
    if(s.front!='|') sums~=s.sum();
    while(!s.empty && s.front=='|'){
        s.popFront();
        sums~=s.sum();
    }

    if(sums.length>1) r~="\n\tprivate{\n\t\tsize_t tag;\n\t\tunion{";
    else r~="\n\t";
    // TODO: only add indirections if necessary?
    r~="Seq!(";
    foreach(sum;sums){
        r~="Tuple!(";
        foreach(tt;sum.types) r~=tt~",";
        r~=")*,";
    }
    r~=") data;";
    if(sums.length>1) r~=" }\n\t}\n";
    else r~="\n";
    r~="\tprivate static make(size_t x,T...)(T args){\n";
    r~="\t\t"~name~" v;\n";
    if(sums.length>1) r~="\t\tv.tag=x;\n";
    r~="\t\tv.data[x]=[tuple(args)].ptr;\n";
    r~="\t\treturn v;\n";
    r~="\t}\n";

    r~="\tstring toString(){\n";
    r~="\t\tstring display(T)(T args){\n";
    r~="\t\t\tstring r;\n";
    r~="\t\t\tforeach(i,a;args.expand)
r~=to!string(args[i])~(i+1==args.length?\"\":\",\");\n";
    r~="\t\t\treturn r;\n";
    r~="\t\t}\n";

    auto genret(size_t i=0){
        return "return
\""~sums[i].name~(sums[i].types.length?"(\"~display(*data["~i.to!string~"])~\")":"")~"\";\n";
    }

    if(sums.length>1){
        r~="\t\tswitch(tag){\n\t\t\tdefault: assert(0);\n";
        foreach(i;0..sums.length){
            r~="\t\t\tcase "~i.to!string~": "~genret(i);
        }
        r~="\t\t}\n";
    }else if(sums.length) r~=genret();
    r~="\t}\n";
    r~="}\n\n";

    foreach(i,sum;sums){
        r~="auto "~sum.name;
        if(hasparams) r~="("~params~")";
        r~="(";
        foreach(j,tt;sum.types) r~=tt~" param"~to!string(j)~",";
        r~="){ return
"~name~(hasparams?"!("~params~")":"")~".make!"~i.to!string~"("~
            iota(sum.types.length).map!(a=>"param"~a.to!string).join(",")~");
}\n";
    }

    r~="auto match(";
    foreach(sum;sums) r~="alias "~sum.name~"case,";
    if(hasparams) r~=params;
    r~=")("~name~(hasparams?"!("~params~")":"")~" arg){\n";
    r~="\tswitch(arg.tag){\n\t\t\tdefault: assert(0);\n";
    foreach(i,sum;sums){
        r~="\t\t\tcase "~to!string(i)~": auto v=*arg.data["~to!string(i)~"];
return "~sum.name~"case(";
        foreach(j,tt;sum.types) r~="v["~to!string(j)~"],";
        r~=");\n";
    }
    r~="\t}\n}\n";

    return r;
}
template ADT(string s){ mixin(create(s)); }

-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
Jun 20 2013
next sibling parent d-bugmail puremagic.com writes:
http://d.puremagic.com/issues/show_bug.cgi?id=10431


bearophile_hugs eml.cc changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |bearophile_hugs eml.cc


--- Comment #1 from bearophile_hugs eml.cc 2013-06-21 04:39:50 PDT ---
Are you able to reduce the code a lot?

-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
Jun 21 2013
prev sibling next sibling parent d-bugmail puremagic.com writes:
http://d.puremagic.com/issues/show_bug.cgi?id=10431


Tim <tim.dlang t-online.de> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |tim.dlang t-online.de


--- Comment #2 from Tim <tim.dlang t-online.de> 2013-06-30 09:50:29 PDT ---
The following code results in the same assertion failure:

struct X(alias Y)
{
}

struct A
{
    int[] data;
}

alias X!(A([])) X1;
alias X!(A([])) X2;

-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
Jun 30 2013
prev sibling next sibling parent d-bugmail puremagic.com writes:
http://d.puremagic.com/issues/show_bug.cgi?id=10431


Kenji Hara <k.hara.pg gmail.com> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
           Keywords|                            |ice, pull


--- Comment #3 from Kenji Hara <k.hara.pg gmail.com> 2013-08-06 18:53:14 PDT ---
https://github.com/D-Programming-Language/dmd/pull/2452

-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
Aug 06 2013
prev sibling next sibling parent d-bugmail puremagic.com writes:
http://d.puremagic.com/issues/show_bug.cgi?id=10431



--- Comment #4 from github-bugzilla puremagic.com 2013-08-11 19:32:12 PDT ---
Commits pushed to master at https://github.com/D-Programming-Language/dmd

https://github.com/D-Programming-Language/dmd/commit/c5d912b75c1636589d6d6a022f1f1c2950202e31
fix Issue 10431 - ICE(DMD 2.063) in struct.c:741 (1)

https://github.com/D-Programming-Language/dmd/commit/e615dbf68f91d54eaa632402744491cbd5b9b577
Merge pull request #2452 from 9rnsr/fix10431

Issue 10431 - ICE(DMD 2.063) in struct.c:741 (1)

-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
Aug 11 2013
prev sibling parent d-bugmail puremagic.com writes:
http://d.puremagic.com/issues/show_bug.cgi?id=10431


Kenji Hara <k.hara.pg gmail.com> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|NEW                         |RESOLVED
         Resolution|                            |FIXED


-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
Aug 12 2013