mirror of
https://github.com/c3lang/c3c.git
synced 2026-02-27 12:01:16 +00:00
Fixing flexible array resolution.
This commit is contained in:
@@ -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;
|
||||
|
||||
@@ -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);
|
||||
|
||||
@@ -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;
|
||||
|
||||
16
test/test_suite/struct/flexible_array_resolve.c3
Normal file
16
test/test_suite/struct/flexible_array_resolve.c3
Normal 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
|
||||
}
|
||||
Reference in New Issue
Block a user