From 8afb5378033e60a745d83142dbde4ef32ec30fbe Mon Sep 17 00:00:00 2001 From: Leo Tenenbaum Date: Sun, 22 Sep 2019 18:58:36 -0400 Subject: elif, else --- types.c | 16 +++++++++++++++- 1 file changed, 15 insertions(+), 1 deletion(-) (limited to 'types.c') diff --git a/types.c b/types.c index cbcd37f..51a801f 100644 --- a/types.c +++ b/types.c @@ -164,7 +164,7 @@ static bool type_of_ident(Typer *tr, Location where, Identifier i, Type *t, bool bool captured = false; if (decl->scope != NULL) for (Block *block = tr->block; block != decl->scope; block = block->parent) { - if (block->kind == BLOCK_FN) { + if (block->flags & BLOCK_FLAG_FN) { captured = true; break; } @@ -360,6 +360,20 @@ static bool type_of_expr(Typer *tr, Expression *e) { return false; } } + if (i->kind == IFEXPR_IF && t->kind != TYPE_VOID) { + /* make sure there's an else at the end of this chain */ + bool has_else = false; + IfExpr *curr = i; + do { + curr = &curr->next_elif->if_; + if (curr->kind == IFEXPR_ELSE) + has_else = true; + } while (curr->next_elif); + if (!has_else) { + err_print(e->where, "non-void if block with no else"); + return false; + } + } } break; case EXPR_CALL: { CallExpr *c = &e->call; -- cgit v1.2.3