commit deb68cd3612201987dad8f19e752b3f2ad0c3426
parent 2c39bc676f1f650539399d5b377cab9232fcfdee
Author: Karl Schultheisz <k@kdsch.org>
Date: Mon, 11 Apr 2022 12:06:59 -0400
parse: reject defs that lack an initializer
Fix a segfault in the checker for incorrect code like
def a: int;
by requiring defs to have an initializer. Refer to spec commit
be14631dfb548a1eebc871eb55e7aca4d9f4f7a0, section 6.11.4.
Signed-off-by: Karl Schultheisz <k@kdsch.org>
Diffstat:
1 file changed, 4 insertions(+), 1 deletion(-)
diff --git a/src/parse.c b/src/parse.c
@@ -2386,7 +2386,10 @@ parse_global_decl(struct lexer *lexer, enum lexical_token mode,
i->type->flags |= TYPE_CONST;
}
- if (lex(lexer, &tok) == T_EQUAL) {
+ if (mode == T_DEF) {
+ want(lexer, T_EQUAL, NULL);
+ i->init = parse_expression(lexer);
+ } else if (lex(lexer, &tok) == T_EQUAL) {
i->init = parse_expression(lexer);
} else {
unlex(lexer, &tok);