"poison" the current function early when a declaration can't be correctly resolved.

This commit is contained in:
Christoffer Lerno
2025-07-19 20:49:26 +02:00
parent 2053f2767b
commit 694d297eb8
8 changed files with 45 additions and 23 deletions

View File

@@ -4639,6 +4639,7 @@ bool sema_analyse_var_decl(SemaContext *context, Decl *decl, bool local)
VarDeclKind kind = decl->var.kind;
bool success = true;
bool is_global = !local;
switch (kind)
{
@@ -4811,25 +4812,26 @@ bool sema_analyse_var_decl(SemaContext *context, Decl *decl, bool local)
CallEnvKind env_kind = context->call_env.kind;
if (is_static) context->call_env.kind = CALL_ENV_FUNCTION_STATIC;
decl->in_init = true;
if (!sema_expr_analyse_assign_right_side(context, NULL, decl->type, init, false, true, NULL))
{
context->call_env.kind = env_kind;
return decl_poison(decl);
}
success = sema_expr_analyse_assign_right_side(context, NULL, decl->type, init, false, true, NULL);
decl->in_init = false;
context->call_env.kind = env_kind;
if (infer_len)
{
if (!success) return decl_poison(decl);
decl->type = type_add_optional(init->type, IS_OPTIONAL(decl));
}
// 2. Check const-ness
if (global_level_var && !expr_is_runtime_const(init))
if (global_level_var)
{
SEMA_ERROR(init, "The expression must be a constant value.");
return decl_poison(decl);
if (!success) return decl_poison(decl);
if (!expr_is_runtime_const(init))
{
SEMA_ERROR(init, "The expression must be a constant value.");
return decl_poison(decl);
}
}
if (!success) goto EXIT_OK;
if (global_level_var || !type_is_abi_aggregate(init->type)) sema_cast_const(init);
if (expr_is_const(init))
{
@@ -4850,7 +4852,7 @@ bool sema_analyse_var_decl(SemaContext *context, Decl *decl, bool local)
{
if (!sema_set_alloca_alignment(context, decl->type, &decl->alignment)) return false;
}
return true;
return success;
}