summaryrefslogtreecommitdiff
path: root/parse/specialize.c
diff options
context:
space:
mode:
authorOri Bernstein <ori@eigenstate.org>2016-01-24 01:10:15 -0800
committerOri Bernstein <ori@eigenstate.org>2016-01-24 01:10:51 -0800
commita555f36aad5963dc600bc0af9433c39ced49b476 (patch)
tree683b08a5dde2079b093c6c97329684895e815bf2 /parse/specialize.c
parentfb8f4a81096140b3c35e0932d20420708a7845ef (diff)
downloadmc-a555f36aad5963dc600bc0af9433c39ced49b476.tar.gz
Fix recursive types nested inside generics.
Diffstat (limited to 'parse/specialize.c')
-rw-r--r--parse/specialize.c19
1 files changed, 13 insertions, 6 deletions
diff --git a/parse/specialize.c b/parse/specialize.c
index 4961230..1db921f 100644
--- a/parse/specialize.c
+++ b/parse/specialize.c
@@ -32,12 +32,12 @@ void addtraits(Type *t, Bitset *traits)
* parameters (type schemes in most literature)
* replaced with type variables that we can unify
* against */
-Type *tyspecialize(Type *t, Htab *tsmap, Htab *delayed)
+Type *tyspecialize(Type *orig, Htab *tsmap, Htab *delayed)
{
- Type *ret, *tmp, **arg;
+ Type *t, *ret, *tmp, **arg, *var;
size_t i, narg;
- t = tysearch(t);
+ t = tysearch(orig);
if (hthas(tsmap, t))
return htget(tsmap, t);
arg = NULL;
@@ -49,20 +49,27 @@ Type *tyspecialize(Type *t, Htab *tsmap, Htab *delayed)
htput(tsmap, t, ret);
break;
case Tygeneric:
+ var = mktyvar(t->loc);
+ htput(tsmap, t, var);
+ for (i = 0; i < t->ngparam; i++)
+ lappend(&arg, &narg, tyspecialize(t->gparam[i], tsmap, delayed));
ret = mktyname(t->loc, t->name, tyspecialize(t->sub[0], tsmap, delayed));
ret->issynth = 1;
- htput(tsmap, t, ret);
- for (i = 0; i < t->ngparam; i++)
- lappend(&ret->arg, &ret->narg, tyspecialize(t->gparam[i], tsmap, delayed));
+ ret->arg = arg;
+ ret->narg = narg;
+ tytab[var->tid] = ret;
break;
case Tyname:
if (!hasparams(t))
return t;
+ var = mktyvar(t->loc);
+ htput(tsmap, t, var);
for (i = 0; i < t->narg; i++)
lappend(&arg, &narg, tyspecialize(t->arg[i], tsmap, delayed));
ret = mktyname(t->loc, t->name, tyspecialize(t->sub[0], tsmap, delayed));
ret->arg = arg;
ret->narg = narg;
+ tytab[var->tid] = ret;
break;
case Tystruct:
ret = tydup(t);