ref: 73b7b068a03c3d58e12cad05dea5a2008af78952
parent: 410752ea2d5f6661e363379d14bd255521ca46e7
author: Ori Bernstein <[email protected]>
date: Wed Oct 3 17:47:54 EDT 2012
Duplicate types correctly. We need to copy all of their members.
--- a/parse/dump.c
+++ b/parse/dump.c
@@ -132,7 +132,7 @@
outnode(n->file.stmts[i], fd, depth + 1);
break;
case Ndecl:
- fprintf(fd, "(did = %zd, isconst = %d, isgeneric = %d, isextern = %d\n, isexport = %d)",
+ fprintf(fd, "(did = %zd, isconst = %d, isgeneric = %d, isextern = %d, isexport = %d)\n",
n->decl.did, n->decl.isconst, n->decl.isgeneric, n->decl.isextern, n->decl.isexport);
outsym(n, fd, depth + 1);
outnode(n->decl.init, fd, depth + 1);
--- a/parse/infer.c
+++ b/parse/infer.c
@@ -138,6 +138,18 @@
return ret;
}
+static Type *tyspecialize(Inferstate *st, Type *t)
+{
+ Htab *ht;
+
+ assert(t->type == Tygeneric);
+ ht = mkht(strhash, streq);
+ t = tyfreshen(st, ht, t);
+ htfree(ht);
+
+ return t;
+}
+
/* Freshens the type of a declaration. */
static Type *freshen(Inferstate *st, Type *t)
{
@@ -484,11 +496,17 @@
b = t;
}
+ if (a->type == Tygeneric)
+ a = tyspecialize(st, a);
+ if (b->type == Tygeneric)
+ b = tyspecialize(st, b);
+
r = NULL;
if (a->type == Tyvar) {
tytab[a->tid] = b;
r = b;
}
+
/* Disallow recursive types */
if (a->type == Tyvar && b->type != Tyvar)
if (occurs(a, b))
--- a/parse/type.c
+++ b/parse/type.c
@@ -53,12 +53,24 @@
r = mktype(t->line, t->type);
r->resolved = 0; /* re-resolving doesn't hurt */
+ r->fixed = 0; /* re-resolving doesn't hurt */
+
r->cstrs = bsdup(t->cstrs);
+ r->cstrlist = memdup(t->cstrlist, t->ncstrlist * sizeof(Node*));
+ r->ncstrlist = t->ncstrlist;
+
+ r->param = memdup(t->param, t->nparam * sizeof(Type*));
+ r->nparam = t->nparam;
+ r->inst = memdup(t->param, t->nparam * sizeof(Type*));
+ r->ninst = t->ninst;
+
+ r->sub = memdup(t->sub, t->nsub * sizeof(Type*));
r->nsub = t->nsub;
r->nmemb = t->nmemb;
- r->sub = memdup(t->sub, t->nsub * sizeof(Type*));
switch (t->type) {
- case Tyunres: r->name = t->name; break;
+ case Tygeneric: r->name = t->name; break;
+ case Tyname: r->name = t->name; break;
+ case Tyunres: r->name = t->name; break;
case Tyarray: r->asize = t->asize; break;
case Typaram: r->pname = strdup(t->pname); break;
case Tystruct: r->sdecls = memdup(t->sdecls, t->nmemb*sizeof(Node*)); break;