diff options
author | Ori Bernstein <ori@eigenstate.org> | 2018-01-25 00:28:07 -0800 |
---|---|---|
committer | Ori Bernstein <ori@eigenstate.org> | 2018-01-25 00:37:13 -0800 |
commit | f1c2aa0d83a485ac3506d007263631a0e338da4d (patch) | |
tree | def2df90c9cce368e3cfa757d45899f6dbbe2911 | |
parent | 2e258c1d7419c170acb950b6af3b3b924c856b2f (diff) | |
download | mc-f1c2aa0d83a485ac3506d007263631a0e338da4d.tar.gz |
Improve error message.
-rw-r--r-- | parse/infer.c | 24 |
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: |