harec

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

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

check: abort on return inside a defer expression

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

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

diff --git a/src/check.c b/src/check.c @@ -1710,6 +1710,9 @@ check_expr_return(struct context *ctx, const struct type *hint) { trenter(TR_CHECK, "return"); + expect(&aexpr->loc, !ctx->deferring, + "Cannot return inside a defer expression"); + expr->type = EXPR_RETURN; expr->result = &builtin_type_void; expr->terminates = true;