From 054fcd2deb7828184a168b718562a9fc30b29453 Mon Sep 17 00:00:00 2001 From: Christoffer Lerno Date: Thu, 5 Feb 2026 13:57:35 +0100 Subject: [PATCH] Update advice when an enum is found with "= 2" and no associated values. --- src/compiler/sema_decls.c | 18 ++++++++++++++++-- 1 file changed, 16 insertions(+), 2 deletions(-) diff --git a/src/compiler/sema_decls.c b/src/compiler/sema_decls.c index 605e46817..e6e4de328 100644 --- a/src/compiler/sema_decls.c +++ b/src/compiler/sema_decls.c @@ -1633,6 +1633,18 @@ static inline bool sema_analyse_enum_param(SemaContext *context, Decl *param) return true; } +static inline void sema_print_enum_to_cenum_error(SemaContext *context, Decl *decl, Expr *arg) +{ + TypeInfo *type_info = decl->enums.type_info; + if (type_info->type == type_int) + { + SEMA_ERROR(arg, "Assigning a value requires the declaration of associated values for the enum. Did you perhaps want C-style enums? In that case use const enums, defined like 'enum %s : const { ... }'", decl->name); + } + else + { + SEMA_ERROR(arg, "Assigning a value requires the declaration of associated values for the enum. Did you perhaps want C-style enums? In that case use const enums, defined like 'enum %s : const %s { ... }'", decl->name, type_to_error_string(type_info->type)); + } +} static inline bool sema_analyse_enum(SemaContext *context, Decl *decl, bool *erase_decl) { if (!sema_analyse_attributes(context, decl, decl->attributes, ATTR_ENUM, erase_decl)) return decl_poison(decl); @@ -1733,7 +1745,8 @@ static inline bool sema_analyse_enum(SemaContext *context, Decl *decl, bool *era { if (!associated_value_count) { - RETURN_SEMA_ERROR(args[0], "There are no associated values defined for this enum. Did you perhaps want C style gap enums? In that case, try enums with inline associated values."); + sema_print_enum_to_cenum_error(context, decl, args[0]); + return false; } RETURN_SEMA_ERROR(args[associated_value_count], "You're adding too many values, only %d associated value%s are defined for '%s'.", associated_value_count, associated_value_count != 1 ? "s" : "", decl->name); } @@ -1758,7 +1771,8 @@ static inline bool sema_analyse_enum(SemaContext *context, Decl *decl, bool *era { if (!associated_value_count) { - RETURN_SEMA_ERROR(args[0], "There are no associated values defined for this enum. Did you perhaps want C style gap enums? In that case, try enums with inline associated values."); + sema_print_enum_to_cenum_error(context, decl, args[0]); + return false; } RETURN_SEMA_ERROR(args[associated_value_count], "You're adding too many values, only %d associated value%s are defined for '%s'.", associated_value_count, associated_value_count != 1 ? "s" : "", decl->name); }