shithub: mc

Download patch

ref: 902b474248683ac2fc03bd4e587dba658b33a309
parent: 1259d97bb9e8389611742f55d6c8308734202ae1
author: Ori Bernstein <[email protected]>
date: Wed Apr 29 20:04:40 EDT 2015

Improve error messages for membership failures.

--- a/parse/infer.c
+++ b/parse/infer.c
@@ -178,6 +178,9 @@
                             else
                                 snprintf(buf, sizeof buf, "<sl:%s>[<e1%s>:<e2:%s>]", t1, t2, t3);
                             break;
+                        case Omemb:
+                            snprintf(buf, sizeof buf, "<%s>.%s", t1, namestr(args[1]));
+                            break;
                         default:
                             snprintf(buf, sizeof buf, "%s:%s", d, t);
                             break;
@@ -1779,8 +1782,12 @@
     } else {
         if (tybase(t)->type == Typtr)
             t = tybase(tf(st, t->sub[0]));
-        if (tybase(t)->type != Tystruct)
-            fatal(n, "type %s does not support member operators near %s", tystr(t), ctxstr(st, n));
+        if (tybase(t)->type != Tystruct) {
+            if (tybase(t)->type == Tyvar)
+                fatal(n, "underspecified type defined on %s:%d used near %s", fname(t->loc), lnum(t->loc), ctxstr(st, n));
+            else
+                fatal(n, "type %s does not support member operators near %s", tystr(t), ctxstr(st, n));
+        }
         nl = t->sdecls;
         for (i = 0; i < t->nmemb; i++) {
             if (!strcmp(namestr(memb), declname(nl[i]))) {
--- a/parse/util.c
+++ b/parse/util.c
@@ -85,7 +85,7 @@
 
 void lfatalv(Srcloc l, char *msg, va_list ap)
 {
-    fprintf(stdout, "%s:%d: ", file->file.files[l.file], l.line);
+    fprintf(stdout, "%s:%d: ", fname(l), lnum(l));
     vfprintf(stdout, msg, ap);
     fprintf(stdout, "\n");
     exit(1);