shithub: mc

Download patch

ref: 5c5b656a306888ea563f10c911e362a0632e7112
parent: 2c85c3a788e346c0ead8e008f159520376d99340
author: Ori Bernstein <ori@eigenstate.org>
date: Sun Jul 12 19:43:21 EDT 2015

Fix up some more type checking.

    We want to check names the same way as other things.

--- a/parse/infer.c
+++ b/parse/infer.c
@@ -895,8 +895,17 @@
     /* if the tyrank of a is 0 (ie, a raw tyvar), just unify.
      * Otherwise, match up subtypes. */
     if ((a->type == b->type || idxhacked(a, b)) && tyrank(a) != 0) {
-        if (a->type == Tyname && !nameeq(a->name, b->name))
-            typeerror(st, a, b, ctx, NULL);
+        if (hasparam(a) && hasparam(b)) {
+            /* Only Tygeneric and Tyname should be able to unify. And they
+             * should have the same names for this to be true. */
+            if (!nameeq(a->name, b->name))
+                typeerror(st, a, b, ctx, NULL);
+            if (a->narg != b->narg)
+                typeerror(st, a, b, ctx, "Incompatible parameter lists");
+            for (i = 0; i < a->narg; i++)
+                unify(st, ctx, a->arg[i], b->arg[i]);
+            r = b;
+        }
         if (a->nsub != b->nsub) {
             verifytraits(st, ctx, a, b);
             if (tybase(a)->type == Tyfunc)
@@ -906,16 +915,6 @@
         }
         for (i = 0; i < b->nsub; i++)
             unify(st, ctx, a->sub[i], b->sub[i]);
-        r = b;
-    } else if (hasparam(a) && hasparam(b)) {
-        /* Only Tygeneric and Tyname should be able to unify. And they
-         * should have the same names for this to be true. */
-        if (!nameeq(a->name, b->name))
-            typeerror(st, a, b, ctx, NULL);
-        if (a->narg != b->narg)
-            typeerror(st, a, b, ctx, "Incompatible parameter lists");
-        for (i = 0; i < a->narg; i++)
-            unify(st, ctx, a->arg[i], b->arg[i]);
         r = b;
     } else if (a->type != Tyvar) {
         typeerror(st, a, b, ctx, NULL);
--- a/parse/type.c
+++ b/parse/type.c
@@ -459,11 +459,11 @@
 
     p = buf;
     end = p + len;
-    p += snprintf(p, end - p, "struct ");
+    p += snprintf(p, end - p, "struct\n");
     for (i = 0; i < t->nmemb; i++) {
         name = declname(t->sdecls[i]);
         ty = tystr(decltype(t->sdecls[i]));
-        p += snprintf(p, end - p, "%s:%s; ", name, ty);
+        p += snprintf(p, end - p, "\t%s:%s\n ", name, ty);
         free(ty);
     }
     p += snprintf(p, end - p, ";;");
@@ -478,15 +478,15 @@
 
     p = buf;
     end = p + len;
-    p += snprintf(p, end - p, "union ");
+    p += snprintf(p, end - p, "union\n");
     for (i = 0; i < t->nmemb; i++) {
         name = namestr(t->udecls[i]->name);
         if (t->udecls[i]->etype) {
             ty = tystr(t->udecls[i]->etype);
-            p += snprintf(p, end - p, "`%s %s; ", name, ty);
+            p += snprintf(p, end - p, "\t`%s %s\n", name, ty);
             free(ty);
         } else {
-            p += snprintf(p, end - p, "`%s; ", name);
+            p += snprintf(p, end - p, "\t`%s\n", name);
         }
     }
     p += snprintf(p, end - p, ";;");