commit ad8ea63a84d097ced8c588efe87b5624f0a0ad09 parent fe4556d224d5b26a65843dcc9fe1cd9ac98785a1 Author: Sebastian <sebastian@sebsite.pw> Date: Wed, 11 Jan 2023 18:25:52 -0500 check: prevent expression from terminating with yield export fn main() void = { { if (true) yield; return; }; void; }; Fixes: https://todo.sr.ht/~sircmpwn/hare/660 Signed-off-by: Sebastian <sebastian@sebsite.pw> Diffstat:
M | src/check.c | | | 2 | +- |
M | tests/33-yield.ha | | | 10 | ++++------ |
2 files changed, 5 insertions(+), 7 deletions(-)
diff --git a/src/check.c b/src/check.c @@ -1675,7 +1675,7 @@ check_expr_compound(struct context *ctx, } expr->terminates = false; - if (lexpr->terminates) { + if (lexpr->terminates && scope->yields == NULL) { expr->terminates = true; if (lexpr->type == EXPR_YIELD) { const char *llabel = lexpr->control.label; diff --git a/tests/33-yield.ha b/tests/33-yield.ha @@ -15,18 +15,16 @@ fn basics() void = { }; fn termination() void = { - // XXX: reject tests have to go first because of - // https://todo.sr.ht/~sircmpwn/hare/660 - assert(compile( - "fn test() void = { let x: int = if (true) { yield; } else 1; };" - ) as exited != EXIT_SUCCESS); - :outer { let x: int = if (true) { yield :outer; } else 1; abort(); }; + + assert(compile( + "fn test() void = { let x: int = if (true) { yield; } else 1; };" + ) as exited != EXIT_SUCCESS); }; fn cast_lowering() void = {