diff options
| author | WormHeamer | 2025-08-11 06:37:59 -0400 |
|---|---|---|
| committer | WormHeamer | 2025-08-11 06:37:59 -0400 |
| commit | 0c45a6cec5df3af1002d1c394a89996646274d61 (patch) | |
| tree | d9ab3bfe2b0dca7bdfa9359a5afc73434b58ac6a | |
| parent | 13c139cc56029ac7108c46fda843950ed1a36f29 (diff) | |
replace separate type checks with non-NULL parse_expr twant
| -rw-r--r-- | main.c | 16 |
1 files changed, 1 insertions, 15 deletions
@@ -58,13 +58,7 @@ void parse_return(Lexer *l, Proc *p) { if (p->ret_type.t == T_NONE) { n = node_new(p, N_RETURN, p->ctrl); } else { - Node *e = parse_expr(l, p, NULL); - if (!type_base_eql(&e->type, &p->ret_type)) { - lex_error_at(l, e->src_pos, LE_ERROR, - str_fmt(&p->arena, "incorrect return type (expected %S, got %S)", - type_desc(&p->ret_type, &p->arena), - type_desc(&e->type, &p->arena))); - } + Node *e = parse_expr(l, p, &p->ret_type); n = node_new(p, N_RETURN, p->ctrl, e); } n = node_peephole(n, p, l); @@ -117,7 +111,6 @@ recurse: if (l->tok == TOK_EQL) { lex_next(l); rhs = parse_expr(l, p, t.t == T_NONE ? NULL : &t); - if (t.t != T_NONE) type_expected(&t, rhs, l); } NameBinding *b = scope_bind(&p->scope, name, rhs, pos, p); if (b) { @@ -155,12 +148,6 @@ void parse_assign(Lexer *l, Proc *p) { lex_error_at(l, pos, LE_ERROR, S("undeclared identifier")); } Node *e = parse_expr(l, p, &b->node->type); - if (!type_base_eql(&e->type, &b->node->type)) { - lex_error_at(l, pos, LE_ERROR, - str_fmt(&p->arena, "tried to assign value of type %S to variable of type %S", - type_desc(&e->type, &p->arena), - type_desc(&b->node->type, &p->arena))); - } if (node_uninit(e)) { lex_error_at(l, e->src_pos, LE_ERROR, str_fmt(&p->arena, "uninitialized %S", @@ -456,7 +443,6 @@ void proc_opt_fwd(Proc *p, Lexer *l, Node *n) { void proc_opt(Proc *p, Lexer *l) { if (p->stop->in.len == 0) { - if (p->ret_type.t != T_NONE) { lex_error(l, LE_ERROR, str_fmt(&p->arena, "no return statement in function expecting %S", type_desc(&p->ret_type, &p->arena))); } |
