From 34a86852c68effb5063a0b29eb48fd882be5d615 Mon Sep 17 00:00:00 2001 From: Christoffer Lerno Date: Tue, 20 Jan 2026 23:07:11 +0100 Subject: [PATCH] Failed to reject void compile time variables, leading to crash. #2781 --- releasenotes.md | 1 + src/compiler/sema_decls.c | 13 +++++++++++++ test/test_suite/compile_time/ct_empty_var_void.c3 | 9 +++++++++ .../typeof_untyped_list.c3 | 1 - 4 files changed, 23 insertions(+), 1 deletion(-) create mode 100644 test/test_suite/compile_time/ct_empty_var_void.c3 diff --git a/releasenotes.md b/releasenotes.md index ac1a1bffa..4e9e862eb 100644 --- a/releasenotes.md +++ b/releasenotes.md @@ -25,6 +25,7 @@ - Broken cast from fault to array pointer #2778. - $typeof untyped list crashes when trying to create typeid from it. #2779 - Recursive constant definition not properly detected, leading to assert #2780 +- Failed to reject void compile time variables, leading to crash. #2781 ### Fixes - Regression with npot vector in struct triggering an assert #2219. diff --git a/src/compiler/sema_decls.c b/src/compiler/sema_decls.c index 33a5c92d9..7cb943950 100644 --- a/src/compiler/sema_decls.c +++ b/src/compiler/sema_decls.c @@ -4739,6 +4739,19 @@ bool sema_analyse_var_decl_ct(SemaContext *context, Decl *decl, bool *check_fail SEMA_ERROR(type_info, "No size could be inferred."); goto FAIL; } + switch (sema_resolve_storage_type(context, decl->type)) + { + case STORAGE_NORMAL: + case STORAGE_COMPILE_TIME: + break; + case STORAGE_ERROR: + goto FAIL; + case STORAGE_VOID: + case STORAGE_WILDCARD: + case STORAGE_UNKNOWN: + SEMA_ERROR(type_info, "Expected a runtime or compile time type with a well-defined zero value."); + goto FAIL; + } decl->var.init_expr = init = expr_new(EXPR_POISONED, decl->span); expr_rewrite_to_const_zero(init, type_no_optional(decl->type)); } diff --git a/test/test_suite/compile_time/ct_empty_var_void.c3 b/test/test_suite/compile_time/ct_empty_var_void.c3 new file mode 100644 index 000000000..39dd2785d --- /dev/null +++ b/test/test_suite/compile_time/ct_empty_var_void.c3 @@ -0,0 +1,9 @@ +fn void a() +{ + void? $y; // #error: Expected a runtime or compile time type with a well-defined zero value +} +fn int main() +{ + void $x; // #error: Expected a runtime or compile time type with a well-defined zero value + +} \ No newline at end of file diff --git a/test/test_suite/compile_time_introspection/typeof_untyped_list.c3 b/test/test_suite/compile_time_introspection/typeof_untyped_list.c3 index 44f761a22..cab5f115e 100644 --- a/test/test_suite/compile_time_introspection/typeof_untyped_list.c3 +++ b/test/test_suite/compile_time_introspection/typeof_untyped_list.c3 @@ -1,5 +1,4 @@ fn void a() { typeid a = $typeof({}); // #error: You cannot take the typeid of a compile time type - var t @safeinfer = mem::new_array($typeof({}), 1); // #error: 'untyped_list' does not have a property or method 'alignof' } \ No newline at end of file