mirror of
https://github.com/c3lang/c3c.git
synced 2026-02-27 12:01:16 +00:00
"poison" the current function early when a declaration can't be correctly resolved.
This commit is contained in:
@@ -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;
|
||||
}
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user