diff options
-rw-r--r-- | main.c | 1 | ||||
-rw-r--r-- | test.toc | 28 | ||||
-rw-r--r-- | types.c | 20 |
3 files changed, 10 insertions, 39 deletions
@@ -8,7 +8,6 @@ /* TODO: -don't allow while/for ret exprs, e.g. for 0..10 { 3; 5 } make #sizeof always take a Type sizeof (not #sizeof) - make new(s) and del functions! @@ -1,31 +1,5 @@ #include "std/io.toc", io; -f ::= fn() int { - total := 0; - for i := 1..10 { - if i % 2 == 0 { continue; } - total += i; - if i == 7 { break; } - } - i := 0; - while { - i += 1; - total += i; - if i == 10 { - break; - } - } - while i < 100 { - i += 1; - if i == 100 { - return total; - } - } - 0 -} - main ::= fn() { - x ::= f(); - io.puti(x); - io.puti(f()); + for i := 0..10 { 3; }; }
\ No newline at end of file @@ -1726,13 +1726,13 @@ static Status types_expr(Typer *tr, Expression *e) { arr_remove_lasta(&tr->in_exprs, tr->allocr); in_header = false; if (!types_block(tr, &fo->body)) goto for_fail; - if (fo->body.ret_expr) { - *t = fo->body.ret_expr->type; - } else { - t->kind = TYPE_VOID; - t->flags |= TYPE_IS_RESOLVED; + err_print(fo->body.ret_expr->where, "for loops can't return values -- you're missing a semicolon (;)"); + goto for_fail; } + + t->kind = TYPE_VOID; + typer_block_exit(tr); break; for_fail: @@ -1882,14 +1882,12 @@ static Status types_expr(Typer *tr, Expression *e) { if (!types_block(tr, &w->body)) ret = false; if (!ret) return false; - 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 { ... })."); + + if (w->body.ret_expr) { + err_print(w->body.ret_expr->where, "while loops can't return values -- you're missing a semicolon (;)"); return false; } - if (w->body.ret_expr) - *t = w->body.ret_expr->type; - else - t->kind = TYPE_VOID; + t->kind = TYPE_VOID; } break; case EXPR_CALL: { CallExpr *c = &e->call; |