ref: f79cf73913ebc6394f5333440bf6d9312c07719a
parent: 3bf2f2e262eebfcc1699d45f6717ae6a07cb32a7
author: Ori Bernstein <ori@eigenstate.org>
date: Wed Jun 1 10:12:00 EDT 2016
Give a proper error for struct types.
--- a/parse/infer.c
+++ b/parse/infer.c
@@ -2219,6 +2219,25 @@
return 1;
}
+static void verifyop(Inferstate *st, Node *n)
+{
+ Type *ty;
+
+ ty = exprtype(n);
+ switch (exprop(n)) {
+ case Ostruct:
+ if (tybase(ty)->type != Tystruct)
+ fatal(n, "wrong type for struct literal: %s\n", tystr(ty));
+ break;
+ case Oarr:
+ if (tybase(ty)->type != Tyarray)
+ fatal(n, "wrong type for struct literal: %s\n", tystr(ty));
+ break;
+ default:
+ break;
+ }
+}
+
/* After type inference, replace all types
* with the final computed type */
static void typesub(Inferstate *st, Node *n, int noerr)
@@ -2290,6 +2309,8 @@
}
for (i = 0; i < n->expr.nargs; i++)
typesub(st, n->expr.args[i], noerr);
+ if (!noerr)
+ verifyop(st, n);
break;
case Nfunc:
pushstab(n->func.scope);