Compiler segfault with struct containing list of structs with an inline member #2416

This commit is contained in:
Christoffer Lerno
2025-08-18 12:19:14 +02:00
parent 5e1bf75621
commit 643aa47e99
5 changed files with 18 additions and 5 deletions

View File

@@ -44,6 +44,7 @@
- Compiler segfault on global slice initialization with null[:0] #2404.
- Use correct allocator in `replace`.
- Regression: 1 character module names would create an error.
- Compiler segfault with struct containing list of structs with an inline member #2416
### Stdlib changes
- Add `==` to `Pair`, `Triple` and TzDateTime. Add print to `Pair` and `Triple`.

View File

@@ -2436,7 +2436,7 @@ void sema_expr_convert_enum_to_int(Expr *expr);
Decl *sema_decl_stack_resolve_symbol(const char *symbol);
Decl *sema_find_decl_in_modules(Module **module_list, Path *path, const char *interned_name);
bool unit_resolve_parameterized_symbol(SemaContext *context, NameResolve *name_resolve);
Decl *sema_resolve_type_method(CanonicalType *type, const char *method_name);
Decl *sema_resolve_type_method(SemaContext *context, CanonicalType *type, const char *method_name);
Decl *sema_resolve_method(Decl *type, const char *method_name);
Decl *sema_resolve_method_only(Decl *type, const char *method_name);
Decl *sema_find_extension_method_in_list(Decl **extensions, Type *type, const char *method_name);

View File

@@ -4638,7 +4638,7 @@ static inline bool sema_expr_analyse_type_access(SemaContext *context, Expr *exp
if (!type_may_have_sub_elements(canonical))
{
Decl *member = sema_resolve_type_method(parent_type->canonical, name);
Decl *member = sema_resolve_type_method(context, parent_type->canonical, name);
if (!decl_ok(member)) return false;
if (!member)
{
@@ -4680,7 +4680,7 @@ static inline bool sema_expr_analyse_type_access(SemaContext *context, Expr *exp
if (!decl_ok(member)) return false;
if (!member)
{
member = sema_resolve_type_method(decl->type, name);
member = sema_resolve_type_method(context, decl->type, name);
if (!decl_ok(member)) return false;
}
if (!member)
@@ -6099,7 +6099,7 @@ CHECK_DEEPER:
// 9. At this point we may only have distinct, struct, union, error, enum, interface
if (!type_may_have_sub_elements(type))
{
Decl *method = sema_resolve_type_method(type, kw);
Decl *method = sema_resolve_type_method(context, type, kw);
if (!method)
{
if (missing_ref) goto MISSING_REF;

View File

@@ -954,7 +954,7 @@ bool sema_resolve_type_decl(SemaContext *context, Type *type)
UNREACHABLE
}
Decl *sema_resolve_type_method(CanonicalType *type, const char *method_name)
Decl *sema_resolve_type_method(SemaContext *context, CanonicalType *type, const char *method_name)
{
RETRY:
if (!type_is_user_defined(type))
@@ -972,9 +972,11 @@ Decl *sema_resolve_type_method(CanonicalType *type, const char *method_name)
}
}
Decl *type_decl = type->decl;
if (!decl_ok(type_decl)) return poisoned_decl;
Methods *methods = type_decl->method_table;
Decl *found = methods ? declptrzero(decltable_get(&methods->method_table, method_name)) : NULL;
if (found || !type_decl->is_substruct) return found;
if (!sema_analyse_decl(context, type_decl)) return poisoned_decl;
switch (type->type_kind)
{
case TYPE_STRUCT:

View File

@@ -0,0 +1,10 @@
import std::collections::list;
struct Module
{
List {ModuleSection} sections;
}
struct ModuleSection
{
inline int data;
}