summaryrefslogtreecommitdiff
path: root/parse/infer.c
diff options
context:
space:
mode:
authorOri Bernstein <ori@eigenstate.org>2018-01-25 00:28:07 -0800
committerOri Bernstein <ori@eigenstate.org>2018-01-25 00:37:13 -0800
commitf1c2aa0d83a485ac3506d007263631a0e338da4d (patch)
treedef2df90c9cce368e3cfa757d45899f6dbbe2911 /parse/infer.c
parent2e258c1d7419c170acb950b6af3b3b924c856b2f (diff)
downloadmc-f1c2aa0d83a485ac3506d007263631a0e338da4d.tar.gz
Improve error message.
Diffstat (limited to 'parse/infer.c')
-rw-r--r--parse/infer.c24
1 files changed, 21 insertions, 3 deletions
diff --git a/parse/infer.c b/parse/infer.c
index bfac296..1c4d39f 100644
--- a/parse/infer.c
+++ b/parse/infer.c
@@ -2562,16 +2562,34 @@ maincompatible(Type *t)
static void
verifyop(Node *n)
{
- Type *ty;
+ Type *ty, *bty;
+ Node *a;
+ char *sa, *sb;
+ size_t i, j;
+ int found;
ty = exprtype(n);
+ bty = tybase(ty);
switch (exprop(n)) {
case Ostruct:
- if (tybase(ty)->type != Tystruct)
+ if (bty->type != Tystruct)
fatal(n, "wrong type for struct literal: %s\n", tystr(ty));
+ for (i = 0; i < n->expr.nargs; i++) {
+ found = 0;
+ a = n->expr.args[i];
+ for (j = 0; j < bty->nmemb; j++) {
+ sa = namestr(a->expr.idx);
+ sb = declname(bty->sdecls[j]);
+ if (!strcmp(sa, sb))
+ found = 1;
+ }
+ if (!found)
+ fatal(n, "type %s has no member %s",
+ tystr(ty), namestr(a->expr.idx));
+ }
break;
case Oarr:
- if (tybase(ty)->type != Tyarray)
+ if (bty->type != Tyarray)
fatal(n, "wrong type for struct literal: %s\n", tystr(ty));
break;
default: