diff options
author | Himbeer <himbeer@disroot.org> | 2024-09-26 22:06:13 +0200 |
---|---|---|
committer | Himbeer <himbeer@disroot.org> | 2024-09-26 22:06:13 +0200 |
commit | 15ab6893227c4eec50539398bd8b65d1ff887cc0 (patch) | |
tree | aef720b3f582cf8163ceea5bbb4764499424c4d3 | |
parent | d3f5f17a26281677bbd6724b653a3860183eb6bf (diff) |
Fix union tag types not being accepted by the parsing procedure
-rw-r--r-- | src/parse.c | 14 |
1 files changed, 13 insertions, 1 deletions
diff --git a/src/parse.c b/src/parse.c index fda8dfd..87588e1 100644 --- a/src/parse.c +++ b/src/parse.c @@ -896,12 +896,24 @@ static bool parse_union(struct lexer *lexer, struct type *out) if (!match(lexer, T_UNION)) { return false; } + + out->desc.un.tag_type = NULL; + if (match(lexer, T_LPAREN)) { + out->desc.un.tag_type = must_malloc(sizeof(struct type)); + if (!parse_type(lexer, out->desc.un.tag_type)) { + error(lex_loc(lexer), "syntax error: expected type"); + } + + if (!match(lexer, T_RPAREN)) { + error(lex_loc(lexer), "syntax error: expected ')'"); + } + } + if (!match(lexer, T_LBRACE)) { error(lex_loc(lexer), "syntax error: expected '{'"); } out->kind = TYP_UNION; - out->desc.un.tag_type = NULL; out->desc.un.alts = must_calloc(1, sizeof(struct type)); out->desc.un.altsz = 1; out->desc.un.altlen = 0; |