Bug where if try would work incorrectly in a macro.

This commit is contained in:
Christoffer Lerno
2024-08-31 23:09:36 +02:00
parent d635cfb90f
commit e6acc56c1f
3 changed files with 5 additions and 3 deletions

View File

@@ -98,6 +98,7 @@
- Memory leak in Object when not using temp allocators.
- Tracking allocator would double the allocations in the report.
- `printf` will now show errors in the output when there are errors.
- Bug where `if try` would work incorrectly in a macro.
### Stdlib changes

View File

@@ -350,6 +350,7 @@ Expr *copy_expr(CopyStruct *c, Expr *source_expr)
case EXPR_TRY_UNWRAP:
if (expr->resolve_status != RESOLVE_DONE)
{
MACRO_COPY_EXPR(expr->try_unwrap_expr.variable);
MACRO_COPY_EXPR(expr->try_unwrap_expr.init);
MACRO_COPY_TYPE(expr->try_unwrap_expr.type);
}
@@ -982,7 +983,8 @@ Decl *copy_decl(CopyStruct *c, Decl *decl)
switch (copy->var.kind)
{
case VARDECL_UNWRAPPED:
MACRO_COPY_DECL(copy->var.alias);
case VARDECL_REWRAPPED:
fixup_decl(c, &copy->var.alias);
break;
case VARDECL_BITMEMBER:
if (copy->var.bit_is_expr)

View File

@@ -712,8 +712,7 @@ static inline bool sema_analyse_try_unwrap(SemaContext *context, Expr *expr)
Decl *decl = ident->identifier_expr.decl;
if (decl->decl_kind != DECL_VAR)
{
SEMA_ERROR(ident, "Expected this to be the name of an optional variable, but it isn't. Did you mistype?");
return false;
RETURN_SEMA_ERROR(ident, "Expected this to be the name of an optional variable, but it isn't. Did you mistype?");
}
if (!IS_OPTIONAL(decl))
{