mirror of
https://github.com/c3lang/c3c.git
synced 2026-02-27 12:01:16 +00:00
Improve errors when a variable fails to properly analyse.
This commit is contained in:
@@ -2306,35 +2306,35 @@ bool sema_analyse_var_decl_ct(SemaContext *context, Decl *decl)
|
||||
if (decl->var.type_info)
|
||||
{
|
||||
SEMA_ERROR(decl->var.type_info, "Compile time type variables may not have a type.");
|
||||
return false;
|
||||
goto FAIL;
|
||||
}
|
||||
if ((init = decl->var.init_expr))
|
||||
{
|
||||
if (!sema_analyse_expr_lvalue_fold_const(context, init)) return false;
|
||||
if (!sema_analyse_expr_lvalue_fold_const(context, init)) goto FAIL;
|
||||
if (init->expr_kind != EXPR_TYPEINFO)
|
||||
{
|
||||
SEMA_ERROR(decl->var.init_expr, "Expected a type assigned to %s.", decl->name);
|
||||
return false;
|
||||
goto FAIL;
|
||||
}
|
||||
}
|
||||
break;
|
||||
case VARDECL_LOCAL_CT:
|
||||
if (decl->var.type_info && !sema_resolve_type_info(context, decl->var.type_info)) return false;
|
||||
if (decl->var.type_info && !sema_resolve_type_info(context, decl->var.type_info)) goto FAIL;
|
||||
if (decl->var.type_info)
|
||||
{
|
||||
decl->type = decl->var.type_info->type->canonical;
|
||||
if (!type_is_builtin(decl->type->type_kind))
|
||||
{
|
||||
SEMA_ERROR(decl->var.type_info, "Compile time variables may only be built-in types.");
|
||||
return false;
|
||||
goto FAIL;
|
||||
}
|
||||
if ((init = decl->var.init_expr))
|
||||
{
|
||||
if (!sema_analyse_expr_rhs(context, decl->type, init, false)) return false;
|
||||
if (!sema_analyse_expr_rhs(context, decl->type, init, false)) goto FAIL;
|
||||
if (!expr_is_constant_eval(init, CONSTANT_EVAL_CONSTANT_VALUE))
|
||||
{
|
||||
SEMA_ERROR(init, "Expected a constant expression assigned to %s.", decl->name);
|
||||
return false;
|
||||
goto FAIL;
|
||||
}
|
||||
}
|
||||
else
|
||||
@@ -2347,11 +2347,11 @@ bool sema_analyse_var_decl_ct(SemaContext *context, Decl *decl)
|
||||
{
|
||||
if ((init = decl->var.init_expr))
|
||||
{
|
||||
if (!sema_analyse_expr(context, init)) return false;
|
||||
if (!sema_analyse_expr(context, init)) goto FAIL;
|
||||
if (!expr_is_constant_eval(init, CONSTANT_EVAL_CONSTANT_VALUE))
|
||||
{
|
||||
SEMA_ERROR(init, "Expected a constant expression assigned to %s.", decl->name);
|
||||
return false;
|
||||
goto FAIL;
|
||||
}
|
||||
decl->type = init->type;
|
||||
}
|
||||
@@ -2367,7 +2367,10 @@ bool sema_analyse_var_decl_ct(SemaContext *context, Decl *decl)
|
||||
|
||||
decl->var.scope_depth = context->active_scope.depth;
|
||||
return sema_add_local(context, decl);
|
||||
|
||||
FAIL:
|
||||
decl->var.scope_depth = context->active_scope.depth;
|
||||
sema_add_local(context, decl);
|
||||
return decl_poison(decl);
|
||||
}
|
||||
/**
|
||||
* Analyse a regular global or local declaration, e.g. int x = 123
|
||||
@@ -2382,8 +2385,6 @@ bool sema_analyse_var_decl(SemaContext *context, Decl *decl, bool local)
|
||||
|
||||
bool is_global = decl->var.kind == VARDECL_GLOBAL || !local;
|
||||
|
||||
if (!sema_analyse_attributes_for_var(context, decl)) return decl_poison(decl);
|
||||
|
||||
if (is_global)
|
||||
{
|
||||
|
||||
@@ -2404,6 +2405,8 @@ bool sema_analyse_var_decl(SemaContext *context, Decl *decl, bool local)
|
||||
if (!sema_add_local(context, decl)) return decl_poison(decl);
|
||||
}
|
||||
|
||||
if (!sema_analyse_attributes_for_var(context, decl)) return decl_poison(decl);
|
||||
|
||||
// 1. Local or global constants: const int FOO = 123.
|
||||
if (!decl->var.type_info)
|
||||
{
|
||||
|
||||
@@ -1 +1 @@
|
||||
#define COMPILER_VERSION "0.3.107"
|
||||
#define COMPILER_VERSION "0.3.108"
|
||||
Reference in New Issue
Block a user