Skip to content

Commit

Permalink
Allow inline enum values to define sizes.
Browse files Browse the repository at this point in the history
  • Loading branch information
lerno committed Feb 3, 2025
1 parent aaa5c0f commit c54c400
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 2 deletions.
2 changes: 1 addition & 1 deletion src/compiler/sema_types.c
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ bool sema_resolve_array_like_len(SemaContext *context, TypeInfo *type_info, Arra
Expr *len_expr = type_info->array.len;

// Analyse it.
if (!sema_analyse_expr(context, len_expr)) return type_info_poison(type_info);
if (!sema_analyse_expr_rhs(context, type_isz, len_expr, false, NULL, false)) return type_info_poison(type_info);

// A constant expression is assumed.
if (!sema_cast_const(len_expr))
Expand Down
2 changes: 1 addition & 1 deletion test/test_suite/arrays/global_array_non_const.c3
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ const int CONSTANT = 1;
int[CONSTANT] a2;
int[3] a3 = { [CONSTANT] = 1 };
const bool B = true;
int[B] c2; // #error: Expected an integer
int[B] c2; // #error: cannot implicitly be converted

int non_constant = 10;
int[non_constant] b; // #error: Expected a constant value as
Expand Down
7 changes: 7 additions & 0 deletions test/test_suite/enumerations/inline_enum_size.c3
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
enum Bar : inline usz
{
FOO,
BAR,
}

int[Bar.BAR] x;

0 comments on commit c54c400

Please sign in to comment.