[Issue 10431] New: ICE(DMD 2.063) in struct.c:741
d-bugmail at puremagic.com
d-bugmail at puremagic.com
Thu Jun 20 15:15:40 PDT 2013
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 at puremagic.com
ReportedBy: timon.gehr at gmx.ch
--- Comment #0 from timon.gehr at 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: -------
More information about the Digitalmars-d-bugs
mailing list