shithub: mc

Download patch

ref: 17dda8e9ba00a68218db115871dad8aa17da146f
parent: 44e5ed3ebbb9c3a8e5e5d809e0f5a6991c4b9570
author: Ori Bernstein <[email protected]>
date: Mon Jul 14 17:42:12 EDT 2014

Fix generic type construction.

--- a/parse/infer.c
+++ b/parse/infer.c
@@ -341,7 +341,6 @@
             unify(st, NULL, t->arg[i], orig->arg[i]);
         }
     }
-    assert(is == isgeneric(orig));
     st->ingeneric -= isgeneric(orig);
     return t;
 }
@@ -727,8 +726,10 @@
 {
     size_t i;
     Type *ft;
+    char *ret, *ctx;
 
     ft = type(st, n->expr.args[0]);
+
     if (ft->type == Tyvar) {
         /* the first arg is the function itself, so it shouldn't be counted */
         ft = mktyfunc(n->line, &n->expr.args[1], n->expr.nargs - 1, mktyvar(n->line));
@@ -747,6 +748,14 @@
     if (i < ft->nsub && ft->sub[i]->type != Tyvalist)
         fatal(n->line, "%s arity mismatch (expected %zd args, got %zd)",
               ctxstr(st, n->expr.args[0]), ft->nsub - 1, i - 1);
+    if (debugopt['u']) {
+        ret = tystr(ft->sub[0]);
+        ctx = ctxstr(st, n->expr.args[0]);
+        printf("Call of %s returns %s\n", ctx, ret);
+        free(ctx);
+        free(ret);
+    }
+
     settype(st, n, ft->sub[0]);
 }
 
--- a/parse/specialize.c
+++ b/parse/specialize.c
@@ -46,26 +46,22 @@
             htput(tsmap, t, ret);
             break;
         case Tyname:
-            if (!hasparams(t)) {
-                ret = t;
-            } else {
-                if (t->narg)
-                    subst = t->arg;
-                else
-                    subst = t->param;
-                for (i = 0; i < t->nparam; i++) {
-                    if (subst[i]->type != Typaram || hthas(tsmap, subst[i]))
-                        continue;
-                    tmp = mktyvar(subst[i]->line);
-                    addtraits(tmp, subst[i]->traits);
-                    htput(tsmap, subst[i], tmp);
-                }
-                ret = mktyname(t->line, t->name, t->param, t->nparam, tyspecialize(t->sub[0], tsmap));
-                ret->issynth = 1;
-                htput(tsmap, t, ret);
-                for (i = 0; i < t->nparam; i++)
-                    lappend(&ret->arg, &ret->narg, tyspecialize(subst[i], tsmap));
+            if (t->narg)
+                subst = t->arg;
+            else
+                subst = t->param;
+            for (i = 0; i < t->nparam; i++) {
+                if (subst[i]->type != Typaram || hthas(tsmap, subst[i]))
+                    continue;
+                tmp = mktyvar(subst[i]->line);
+                addtraits(tmp, subst[i]->traits);
+                htput(tsmap, subst[i], tmp);
             }
+            ret = mktyname(t->line, t->name, t->param, t->nparam, tyspecialize(t->sub[0], tsmap));
+            ret->issynth = 1;
+            htput(tsmap, t, ret);
+            for (i = 0; i < t->nparam; i++)
+                lappend(&ret->arg, &ret->narg, tyspecialize(subst[i], tsmap));
             break;
         case Tystruct:
             ret = tydup(t);
binary files /dev/null b/test/genericmake differ
--- a/test/tests
+++ b/test/tests
@@ -85,6 +85,7 @@
 B genericmatch	E	15
 B genericrec	E	0
 # B genericchain	P	"val = 123" ## BUGGERED
+B genericmake	P	"val = 123"
 B stdopt-some	E	42
 B stdopt-none	E	42
 B stdopt-mk	E	42