harec

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

commit b201f877a1bb6fad5beae7a7d4ebce450ddbfff8
parent ece814f70d1a26d827652bddca5723307745a6e9
Author: Drew DeVault <sir@cmpwn.com>
Date:   Sat, 13 Feb 2021 14:15:47 -0500

gen: handle default case terminating

Diffstat:
Msrc/check.c | 6++++--
Msrc/gen.c | 8++++++--
2 files changed, 10 insertions(+), 4 deletions(-)

diff --git a/src/check.c b/src/check.c @@ -1448,7 +1448,8 @@ check_expr_match(struct context *ctx, struct ast_match_case *acase = aexpr->match.cases; while (_case) { expect(&acase->value->loc, - type_is_assignable(expr->result, _case->value->result), + _case->value->terminates || + type_is_assignable(expr->result, _case->value->result), "Match case is not assignable to result type"); _case->value = lower_implicit_cast( expr->result, _case->value); @@ -1781,7 +1782,8 @@ check_expr_switch(struct context *ctx, struct ast_switch_case *acase = aexpr->_switch.cases; while (_case) { expect(&acase->value->loc, - type_is_assignable(expr->result, _case->value->result), + _case->value->terminates || + type_is_assignable(expr->result, _case->value->result), "Switch case is not assignable to result type"); _case->value = lower_implicit_cast( expr->result, _case->value); diff --git a/src/gen.c b/src/gen.c @@ -1897,7 +1897,9 @@ gen_match_tagged(struct gen_context *ctx, push(&ctx->current->body, &flabel); } - if (_default) { + if (_default && _default->value->terminates) { + gen_expression(ctx, _default->value, NULL); + } else if (_default) { gen_expression(ctx, _default->value, out); } @@ -2249,7 +2251,9 @@ gen_expr_switch(struct gen_context *ctx, push(&ctx->current->body, &flabel); } - if (_default) { + if (_default && _default->value->terminates) { + gen_expression(ctx, _default->value, NULL); + } else if (_default) { gen_expression(ctx, _default->value, out); }