commit 95aba73afa70bb5d314541b98d003988c96398d6
parent 5c9990c863e8eaf8eb47d23b4fb9a73c9ce8056c
Author: Karl Schultheisz <k@kdsch.org>
Date: Tue, 26 Apr 2022 12:13:34 -0400
check: require init'r for context-defined arrays
Fix segfaults for incorrect code such as
let x: [_]int;
by rejecting declarations that lack an initializer.
Signed-off-by: Karl Schultheisz <k@kdsch.org>
Diffstat:
1 file changed, 3 insertions(+), 0 deletions(-)
diff --git a/src/check.c b/src/check.c
@@ -3323,6 +3323,9 @@ scan_global(struct context *ctx, const struct ast_global_decl *decl)
if (decl->type->storage == STORAGE_ARRAY
&& decl->type->array.contextual) {
+ expect(&decl->type->loc, decl->init,
+ "Cannot infer array length without an initializer");
+
// TODO: Free initialier
struct expression *initializer =
xcalloc(1, sizeof(struct expression));