From a9810c2281a2c4fc2265aa8c59fa9bf101e3a3b5 Mon Sep 17 00:00:00 2001 From: WormHeamer Date: Sun, 10 Aug 2025 05:20:40 -0400 Subject: better error reporting around uninitialized values --- ir.c | 40 +++------------------------------------- 1 file changed, 3 insertions(+), 37 deletions(-) (limited to 'ir.c') diff --git a/ir.c b/ir.c index b0b90f5..0e8e097 100644 --- a/ir.c +++ b/ir.c @@ -359,19 +359,9 @@ static int type_ok(Node *n) { } } -/* TODO: make it so - * func foo(a, b i64) i64 { - * let x i64 - * if a < b { - * return 0 - * } else { - * x := 3 - * } - * return x - * } - * doesn't throw warnings (e.g. don't generate phi nodes if one scope is - * guaranteed to return early) - */ +void type_check(Node *n, Lexer *l) { + if (!type_ok(n)) type_err(n, l); +} int node_uninit(Node *n) { return n->op == N_UNINIT; @@ -386,27 +376,3 @@ int node_maybe_uninit(Node *n) { } return 0; } - -void uninit_check(Node *n, Lexer *l) { - if (NMASK(n->op) & ~NM_PHI) { - for (int i = 0; i < n->in.len; i++) { - Node *o = IN(n, i); - if (!o) continue; - if (node_uninit(o)) { - fprintf(stderr, "%s\n", node_type_name(n->op)); - lex_error_at(l, o->src_pos, LE_WARN, - str_fmt(&l->arena, "uninitialized %S", - type_desc(&IN(n,i)->type, &l->arena))); - } else if (node_maybe_uninit(o)) { - lex_error_at(l, o->src_pos, LE_WARN, - str_fmt(&l->arena, "possibly uninitialized %S", - type_desc(&o->type, &l->arena))); - } - } - } -} - -void type_check(Node *n, Lexer *l) { - uninit_check(n, l); - if (!type_ok(n)) type_err(n, l); -} -- cgit v1.2.3