Merge pull request #7416 from kalsprite/distinct_alias_cycle

Fix compiler segfault on `distinct` of a type alias that cycles back
This commit is contained in:
Jeroen van Rijn
2026-08-22 02:10:53 +02:00
committed by GitHub
2 changed files with 6 additions and 2 deletions

View File

@@ -473,7 +473,11 @@ gb_internal void check_type_decl(CheckerContext *ctx, Entity *e, Ast *init_expr,
check_type_path_pop(ctx);
Type *base = base_type(bt);
if (is_distinct && bt->kind == Type_Named && base->kind == Type_Enum) {
if (base == nullptr) {
// `bt` is a named type that is still being checked, e.g. a cycle back through a
// pointer or slice, so chain to it and let it resolve when it does.
base = bt;
} else if (is_distinct && bt->kind == Type_Named && base->kind == Type_Enum) {
base = clone_enum_type(ctx, base, named);
}
named->Named.base = base;

View File

@@ -4139,7 +4139,7 @@ gb_internal Type *check_type_expr(CheckerContext *ctx, Ast *e, Type *named_type)
}
#endif
if (type->kind == Type_Named && type->Named.base == nullptr || is_type_typed(type)) {
if (type->kind == Type_Named && base_type(type) == nullptr || is_type_typed(type)) {
add_type_and_value(ctx, e, Addressing_Type, type, empty_exact_value);
} else {
gbString name = type_to_string(type);