harec

Unnamed repository; edit this file 'description' to name the repository.
Log | Files | Refs | README | LICENSE

commit c019c64b4531f1cad0b8c022624ab65e54a39833
parent f5f439ac7839b1cb75ddd4e05ac111113c38e2fc
Author: Bor Grošelj Simić <bor.groseljsimic@telemach.net>
Date:   Sat, 27 Feb 2021 13:57:09 +0100

check: abort on error propagation inside a defer

Display a diagnostic message and abort when encountering expressions
like `defer foo()?;` instead of segfaulting.

Diffstat:
Msrc/check.c | 4+++-
1 file changed, 3 insertions(+), 1 deletion(-)

diff --git a/src/check.c b/src/check.c @@ -1590,6 +1590,8 @@ check_expr_propagate(struct context *ctx, expect(&aexpr->loc, type_dealias(intype)->storage == STORAGE_TAGGED, "Cannot use error propagation with non-tagged type"); + expect(&aexpr->loc, !ctx->deferring, + "Cannot use error propagation in a defer expression"); struct type_tagged_union result_tagged = {0}; struct type_tagged_union *tagged = &result_tagged, @@ -1685,7 +1687,7 @@ check_expr_propagate(struct context *ctx, case_err->value->type = EXPR_RETURN; case_err->value->terminates = true; case_err->value->result = &builtin_type_void; - struct expression *rval = + struct expression *rval = xcalloc(1, sizeof(struct expression)); rval->type = EXPR_ACCESS; rval->access.type = ACCESS_IDENTIFIER;