Fixing flexible array resolution.

This commit is contained in:
Christoffer Lerno
2024-06-21 18:36:39 +02:00
parent e8e615f4db
commit 684850dda1
4 changed files with 28 additions and 0 deletions

View File

@@ -1662,6 +1662,7 @@ struct CompilationUnit_
HTable local_symbols;
int lambda_count;
Decl **local_method_extensions;
TypeInfo **check_type_variable_array;
struct
{
void *debug_file;

View File

@@ -592,6 +592,9 @@ void sema_analysis_pass_decls(Module *module)
{
sema_analyse_decl(&context, unit->generic_defines[i]);
}
FOREACH_BEGIN(TypeInfo *info, unit->check_type_variable_array)
sema_check_type_variable_array(&context, info);
FOREACH_END();
sema_context_destroy(&context);
}
DEBUG_LOG("Pass finished with %d error(s).", global_context.errors_found);

View File

@@ -101,8 +101,11 @@ static inline bool sema_resolve_array_type(SemaContext *context, TypeInfo *type,
if (!sema_resolve_type(context, type->array.base, resolve_type_kind)) return type_info_poison(type);
Type *distinct_base = type_flatten(type->array.base->type);
// We don't want to allow arrays with flexible members
if (distinct_base->type_kind == TYPE_STRUCT)
{
// If the struct is resolved, we can check immediately
if (distinct_base->decl->resolve_status == RESOLVE_DONE)
{
if (distinct_base->decl->has_variable_array)
@@ -111,6 +114,11 @@ static inline bool sema_resolve_array_type(SemaContext *context, TypeInfo *type,
return type_info_poison(type);
}
}
else
{
// Otherwise we have to defer it:
vec_add(context->unit->check_type_variable_array, type);
}
}
TypeInfo *base_info = type->array.base;
Type *base = base_info->type;

View File

@@ -0,0 +1,16 @@
struct Abc
{
Foo[4] x; // #error: Arrays of structs with flexible array members
}
struct Foo
{
int a;
int[*] x;
}
struct Foo2
{
int a;
int[*] x, y; // #error: must be the last element
}