Ensure type is checked before analysis of compound literals. #919

This commit is contained in:
Christoffer Lerno
2023-08-11 18:15:39 +02:00
parent 3e765a3f3e
commit f0d4c4d2ce
3 changed files with 7 additions and 3 deletions

View File

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

View File

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

View File

@@ -0,0 +1 @@
const IS_ARCH_LITTLE_ENDIAN = (uint)(UIntLE{(uint)1}.val) == 1; // #error: This expression cannot be evaluated at compile time