summaryrefslogtreecommitdiff
path: root/types.c
diff options
context:
space:
mode:
Diffstat (limited to 'types.c')
-rw-r--r--types.c11
1 files changed, 9 insertions, 2 deletions
diff --git a/types.c b/types.c
index f0b3107..2a7fd22 100644
--- a/types.c
+++ b/types.c
@@ -607,12 +607,19 @@ static bool types_expr(Typer *tr, Expression *e) {
case EXPR_WHILE: {
WhileExpr *w = &e->while_;
bool ret = true;
- if (!types_expr(tr, w->cond))
+ if (w->cond && !types_expr(tr, w->cond))
ret = false;
if (!types_block(tr, &w->body))
ret = false;
if (!ret) return false;
- *t = w->body.ret_expr->type;
+ if (w->cond != NULL && w->body.ret_expr != NULL) {
+ err_print(e->where, "A finite loop can't have a return expression (for an infinite loop, use while { ... }).");
+ return false;
+ }
+ if (w->body.ret_expr)
+ *t = w->body.ret_expr->type;
+ else
+ t->kind = TYPE_VOID;
} break;
case EXPR_CALL: {
CallExpr *c = &e->call;