harec

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

commit 27d7e12d8a29f12c7cdbf396bbeda793447fb369
parent 608cc0ae5d8ac1d85f9f08893feb946754928b38
Author: Eyal Sawady <ecs@d2evs.net>
Date:   Mon, 13 Dec 2021 12:24:45 +0000

check: disallow deferring in function scopes

This previously segfaulted in gen, handle it gracefully in check instead

Signed-off-by: Eyal Sawady <ecs@d2evs.net>

Diffstat:
Msrc/check.c | 5+++++
1 file changed, 5 insertions(+), 0 deletions(-)

diff --git a/src/check.c b/src/check.c @@ -1508,6 +1508,11 @@ check_expr_defer(struct context *ctx, "Cannot defer within another defer expression."); return; } + if (ctx->scope->class == SCOPE_FUNC) { + error(ctx, aexpr->loc, expr, + "Cannot defer in a function scope"); + return; + } expr->type = EXPR_DEFER; expr->result = &builtin_type_void; expr->defer.deferred = xcalloc(1, sizeof(struct expression));