mirror of
https://github.com/c3lang/c3c.git
synced 2026-02-27 12:01:16 +00:00
Ensure type is checked before analysis of compound literals. #919
This commit is contained in:
@@ -7663,14 +7663,16 @@ static inline bool sema_expr_analyse_builtin(SemaContext *context, Expr *expr, b
|
||||
|
||||
static inline bool sema_expr_analyse_compound_literal(SemaContext *context, Expr *expr)
|
||||
{
|
||||
if (!sema_resolve_type_info(context, expr->expr_compound_literal.type_info)) return false;
|
||||
Type *type = expr->expr_compound_literal.type_info->type;
|
||||
TypeInfo *type_info = expr->expr_compound_literal.type_info;
|
||||
if (!sema_resolve_type_info(context, type_info)) return false;
|
||||
Type *type = type_info->type;
|
||||
if (type_is_optional(type))
|
||||
{
|
||||
SEMA_ERROR(expr->expr_compound_literal.type_info,
|
||||
SEMA_ERROR(type_info,
|
||||
"The type here should always be written as a plain type and not an optional, please remove the '!'.");
|
||||
return false;
|
||||
}
|
||||
if (!sema_resolve_type_structure(context, type, type_info->span)) return false;
|
||||
if (!sema_expr_analyse_initializer_list(context, type, expr->expr_compound_literal.initializer)) return false;
|
||||
expr_replace(expr, expr->expr_compound_literal.initializer);
|
||||
return true;
|
||||
|
||||
@@ -566,6 +566,7 @@ bool sema_expr_analyse_initializer_list(SemaContext *context, Type *to, Expr *ex
|
||||
assert(to);
|
||||
Type *flattened = type_flatten(to);
|
||||
bool is_zero_init = expr->expr_kind == EXPR_INITIALIZER_LIST && !vec_size(expr->initializer_list);
|
||||
if (!sema_resolve_type_structure(context, to, expr->span)) return false;
|
||||
switch (flattened->type_kind)
|
||||
{
|
||||
case TYPE_UNTYPED_LIST:
|
||||
|
||||
1
test/test_suite/initialize/init_non_resolved_type.c3
Normal file
1
test/test_suite/initialize/init_non_resolved_type.c3
Normal file
@@ -0,0 +1 @@
|
||||
const IS_ARCH_LITTLE_ENDIAN = (uint)(UIntLE{(uint)1}.val) == 1; // #error: This expression cannot be evaluated at compile time
|
||||
Reference in New Issue
Block a user