shithub: mc

Download patch

ref: 3cacd3499c4b91c972d1e2daede8a9c8e3efe247
parent: a7fd1a3b542c98c29c18c44078e3c0170591692a
author: Ori Bernstein <[email protected]>
date: Tue Feb 11 06:02:42 EST 2014

Actually print the traits that we are missing.

    It makes for easier debugging.

--- a/parse/infer.c
+++ b/parse/infer.c
@@ -544,6 +544,10 @@
 /* Merges the constraints on types */
 static void mergetraits(Inferstate *st, Node *ctx, Type *a, Type *b)
 {
+    size_t i, n;
+    char *sep;
+    char buf[1024];
+
     if (b->type == Tyvar) {
         /* make sure that if a = b, both have same traits */
         if (a->traits && b->traits)
@@ -554,8 +558,14 @@
             a->traits = bsdup(b->traits);
     } else {
         if (!traitcheck(a, b)) {
-            /* FIXME: say WHICH constraints we're missing */
-            fatal(ctx->line, "%s missing constraints for %s near %s", tystr(b), tystr(a), ctxstr(st, ctx));
+            sep = "";
+            n = 0;
+            for (i = 0; bsiter(a->traits, &i); i++) {
+                if (!bshas(b->traits, i))
+                    n += snprintf(buf + n, sizeof(buf) - n, "%s%s", sep, namestr(traittab[i]->name));
+                sep = ",";
+            }
+            fatal(ctx->line, "%s missing constraints %s for %s near %s", tystr(b), buf, tystr(a), ctxstr(st, ctx));
         }
     }
 }