Failed to reject void compile time variables, leading to crash. #2781

This commit is contained in:
Christoffer Lerno
2026-01-20 23:07:11 +01:00
parent 52afbdbde9
commit 34a86852c6
4 changed files with 23 additions and 1 deletions

View File

@@ -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.

View File

@@ -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));
}

View File

@@ -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
}

View File

@@ -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'
}