Skip to content

Commit

Permalink
Fixes with error handling recursive @tag #1583.
Browse files Browse the repository at this point in the history
  • Loading branch information
lerno committed Oct 30, 2024
1 parent 8274406 commit b7a23e5
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 1 deletion.
1 change: 1 addition & 0 deletions releasenotes.md
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@
- `HashMap.copy_keys` did not properly copy keys which needed to be allocated #1569
- Named vector component access would not fold at compile time. #1574
- `$define` would occasionally not properly evaluate declarations it encountered.
- Fixes with error handling recursive `@tag` #1583.

### Stdlib changes
- Remove unintended print of `char[]` as String
Expand Down
9 changes: 8 additions & 1 deletion src/compiler/sema_expr.c
Original file line number Diff line number Diff line change
Expand Up @@ -933,6 +933,11 @@ static inline bool sema_identifier_find_possible_inferred(SemaContext *context,
{
if (to->canonical->type_kind != TYPE_ENUM && to->canonical->type_kind != TYPE_FAULTTYPE) return false;
Decl *parent_decl = to->canonical->decl;
if (!decl_ok(parent_decl))
{
expr_poison(expr);
return true;
}
switch (parent_decl->decl_kind)
{
case DECL_ENUM:
Expand Down Expand Up @@ -973,7 +978,7 @@ static inline bool sema_expr_analyse_identifier(SemaContext *context, Type *to,
// Just start with inference
if (!expr->identifier_expr.path && to)
{
if (sema_identifier_find_possible_inferred(context, to, expr)) return true;
if (sema_identifier_find_possible_inferred(context, to, expr)) return expr_ok(expr);
}

Decl *decl = sema_find_path_symbol(context, expr->identifier_expr.ident, expr->identifier_expr.path);
Expand Down Expand Up @@ -3635,6 +3640,7 @@ static inline bool sema_expr_analyse_type_access(SemaContext *context, Expr *exp
if (!sema_expr_analyse_enum_constant(context, expr, name, decl))
{
if (missing_ref) goto MISSING_REF;
if (!decl_ok(decl)) return false;
SEMA_ERROR(expr, "'%s' has no enumeration value '%s'.", decl->name, name);
return false;
}
Expand All @@ -3648,6 +3654,7 @@ static inline bool sema_expr_analyse_type_access(SemaContext *context, Expr *exp
if (!sema_expr_analyse_enum_constant(context, expr, name, decl))
{
if (missing_ref) goto MISSING_REF;
if (decl_poison(decl)) return false;
SEMA_ERROR(expr, "'%s' has no error value '%s'.", decl->name, name);
return false;
}
Expand Down
13 changes: 13 additions & 0 deletions test/test_suite/compile_time_introspection/recursive_tag.c3
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
enum Test @tag("test", Test.FOO) {FOO} // #error: Recursive definition of 'Test'

def @Test(Foo val) = {};

enum Foo @tag("test", Foo.BAR) // #error: Recursive definition of 'Foo'
{
BAR,
BAZ
}

fn void main() @Test(BAR)
{
}

0 comments on commit b7a23e5

Please sign in to comment.