Improve error message when encountering recursively defined structs. #2146

This commit is contained in:
Christoffer Lerno
2025-05-19 21:36:47 +02:00
parent 9052f07c19
commit 7fcc91edc8
3 changed files with 15 additions and 0 deletions

View File

@@ -546,6 +546,11 @@ static bool sema_analyse_struct_members(SemaContext *context, Decl *decl)
// Grab the alignment of the member type
AlignSize member_type_alignment;
if (type_is_user_defined(member_type) && member_type->decl->resolve_status == RESOLVE_RUNNING)
{
SEMA_ERROR(member, "Recursive defintion of %s.", type_quoted_error_string(member_type));
return decl_poison(decl);
}
if (!sema_set_abi_alignment(context, member->type, &member_type_alignment)) return decl_poison(decl);
// And get the natural alignment
AlignSize member_natural_alignment = sema_get_max_natural_alignment(member->type);