diff --git a/releasenotes.md b/releasenotes.md index 043210ad2..c848a9d12 100644 --- a/releasenotes.md +++ b/releasenotes.md @@ -63,6 +63,7 @@ - Fix to `temp_directory` on Windows #2762. - Too little memory reserved when printing backtrace on Darwin #2698. - In some cases, a type would not get implicitly converted to a typeid #2764. +- Assert on defining a const fault enum with enumerator and fault of the same name. #2732 ### Stdlib changes - Add `ThreadPool` join function to wait for all threads to finish in the pool without destroying the threads. diff --git a/src/compiler/sema_decls.c b/src/compiler/sema_decls.c index 720a2f537..5a77335df 100644 --- a/src/compiler/sema_decls.c +++ b/src/compiler/sema_decls.c @@ -1777,7 +1777,7 @@ ERR: bool sema_analyse_const_enum_constant_val(SemaContext *context, Decl *decl) { Expr *value = decl->enum_constant.value; - if (!sema_analyse_inferred_expr(context, decl->type, value,NULL)) return decl_poison(decl); + if (!sema_analyse_inferred_expr(context, decl->type, value, NULL)) return decl_poison(decl); if (!expr_is_runtime_const(value)) { SEMA_ERROR(value, "Expected an constant enum value."); diff --git a/src/compiler/sema_expr.c b/src/compiler/sema_expr.c index 02b62eece..bbaa48de8 100644 --- a/src/compiler/sema_expr.c +++ b/src/compiler/sema_expr.c @@ -19,7 +19,7 @@ expr_temp__->resolve_status = RESOLVE_DONE; \ return true; \ case RESOLVE_RUNNING: \ - SEMA_ERROR(expr, "Recursive resolution of expression"); \ + SEMA_ERROR(expr, "Recursive resolution of expression."); \ return expr_poison(expr_temp__); \ case RESOLVE_DONE: \ return expr_ok(expr_temp__); \ @@ -1177,7 +1177,7 @@ static inline bool sema_expr_analyse_enum_constant(SemaContext *context, Expr *e if (enum_constant->enum_constant.is_raw) { expr_replace(expr, copy_expr_single(enum_constant->enum_constant.value)); - return true; + return sema_analyse_expr_rvalue(context, expr); } expr->expr_kind = EXPR_CONST; expr->const_expr.const_kind = CONST_ENUM; diff --git a/test/test_suite/enumerations/recursive_const_enum.c3 b/test/test_suite/enumerations/recursive_const_enum.c3 new file mode 100644 index 000000000..8f1082682 --- /dev/null +++ b/test/test_suite/enumerations/recursive_const_enum.c3 @@ -0,0 +1,10 @@ +module main; + +faultdef F; + +enum Foo : const fault +{ + F = F // #error: Recursive resolution of expression +} + +fn void main() {} \ No newline at end of file