diff options
Diffstat (limited to 'bootstrap')
| -rw-r--r-- | bootstrap/cgen.c | 2 | ||||
| -rw-r--r-- | bootstrap/parse.c | 8 | ||||
| -rw-r--r-- | bootstrap/test2.cff | 8 |
3 files changed, 16 insertions, 2 deletions
diff --git a/bootstrap/cgen.c b/bootstrap/cgen.c index 8e2fef9..db477fd 100644 --- a/bootstrap/cgen.c +++ b/bootstrap/cgen.c @@ -684,6 +684,8 @@ defctype(const struct type *ty, void *_) { pri("typedef %s %s %s;\n", kind, *cname, *cname); if (!ty->agg.fwd) { pri("%s %s {\n", kind, *cname); + if (!ty->agg.flds.n) + pri("char _;\n"); for (int i = 0; i < ty->agg.flds.n; ++i) { struct aggfield fld = ty->agg.flds.d[i]; defctype(ty->agg.flds.d[i].ty, NULL); diff --git a/bootstrap/parse.c b/bootstrap/parse.c index 59d3b5f..02980cc 100644 --- a/bootstrap/parse.c +++ b/bootstrap/parse.c @@ -2327,7 +2327,8 @@ parsefn(struct decl *decl, struct parser *P) { putdecl(P, tok.span, &decl); } fn->body = xcalloc(1, sizeof *fn->body); - *fn->body = parseblock(P); + WITH_TMPCHANGE(int, P->varid, 0) + *fn->body = parseblock(P); popenv(P); } } @@ -2599,8 +2600,11 @@ parseagg(struct parser *P, const char *name, int kind, struct decl **retdecl) { } } + if (!flds.length && kind == TYeunion) + fatal(P, tok.span, "enum union must have at least 1 variant"); + struct type *ppty = (struct type *)pty; - ppty->size = ALIGNUP(size, align); + ppty->size = size ? ALIGNUP(size, align) : 1; ppty->align = align; vec_slice_cpy(&ppty->agg.flds, &flds); diff --git a/bootstrap/test2.cff b/bootstrap/test2.cff index c0fafc5..b94a74e 100644 --- a/bootstrap/test2.cff +++ b/bootstrap/test2.cff @@ -24,6 +24,11 @@ enum union Value { Flo f32, } +enum union Option<T> { + None, + Some T +} + extern fn main() void { let n Node<int> = {#null, 0}; let n Node<int> = {&n, 1}; @@ -41,6 +46,9 @@ extern fn main() void { *f += 1.0f; } + let x = Option<int>:Some 3; + let x = Option<f32>:None; + printf("n %d\n", n.value); printf("n link %d\n", n.link.value); |