diff options
Diffstat (limited to 'bootstrap/parse.c')
| -rw-r--r-- | bootstrap/parse.c | 16 |
1 files changed, 16 insertions, 0 deletions
diff --git a/bootstrap/parse.c b/bootstrap/parse.c index 9ab1b53..e32a2a3 100644 --- a/bootstrap/parse.c +++ b/bootstrap/parse.c @@ -786,6 +786,7 @@ parsearrini(struct parser *P, const struct type *ty) { fatal(P, e.span, "excess elements in array initializer"); vec_push(&args, ((struct iniarg) { .idx = iota++, e })); + ex.ini.maxn = MAX(ex.ini.maxn, iota - 1); if (!lexmatch(P, &tok, ',')) { lexexpect(P, '}'); @@ -1511,6 +1512,21 @@ parsevardecl(decl_yielder_t yield, void *yarg, struct parser *P) { fatal(P, tok.span, "incompatible initializer type (%t, expected %t)", ini->ty, ty); + if (ty->t == TYarr && ty->length < 0) { + struct type ty2 = *ty; + if (ini->t == Ezeroini) { + ty2.length = 0; + } else if (ini->t == Eini) { + ty2.length = ini->ini.maxn + 1; + } else { + fatal(P, ini->span, + "initializer of inferred-length array must be compound literal"); + } + ty2.size = ty->child->size * ty2.length; + ty2.align = ty->child->align; + ty = interntype(ty2); + } + if (!completetype(ty)) fatal(P, tok.span, "let `%s': variable type %t is incomplete", name, ty); |