Move array size checking to verification.
We don't necessarily know the type of the array index until
after substituting, so things like sizeof() or constant
folding may not work.
@@ -2031,9 +2031,6 @@ tyfix(Node *ctx, Type *orig, int noerr)
t->fixed = 1;
if (t->type == Tyarray) {
typesub(t->asize, noerr);
- t->asize = fold(t->asize, 1);
- if (t->asize && exprop(t->asize) != Olit)
- fatal(t->asize, "nonconstant array size near %s\n", ctxstr(t->asize));
} else if (t->type == Tystruct) {
inaggr++;
for (i = 0; i < t->nmemb; i++)
@@ -2593,6 +2590,7 @@ applytraits(Node *f)
void
verify(Node *f)
{
+ Type *t;
Node *n;
size_t i;
@@ -2607,6 +2605,14 @@ verify(Node *f)
namestr(n->impl.traitname), tystr(n->impl.type));
}
}
+ for (i = 0; i < ntypes; i++) {
+ t = types[i];
+ if (t->type != Tyarray)
+ continue;
+ t->asize = fold(t->asize, 1);
+ if (t->asize && exprop(t->asize) != Olit)
+ fatal(t->asize, "nonconstant array size near %s\n", ctxstr(t->asize));
+ }
}
void
