diff --git a/releasenotes.md b/releasenotes.md index 18d3ef850..7db17306c 100644 --- a/releasenotes.md +++ b/releasenotes.md @@ -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 diff --git a/src/compiler/copying.c b/src/compiler/copying.c index a53c7804e..3c702c84a 100644 --- a/src/compiler/copying.c +++ b/src/compiler/copying.c @@ -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, ©->var.alias); break; case VARDECL_BITMEMBER: if (copy->var.bit_is_expr) diff --git a/src/compiler/sema_stmts.c b/src/compiler/sema_stmts.c index 064b98558..97e3ae1c8 100644 --- a/src/compiler/sema_stmts.c +++ b/src/compiler/sema_stmts.c @@ -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)) {