diff options
| author | WormHeamer | 2025-08-10 05:20:40 -0400 |
|---|---|---|
| committer | WormHeamer | 2025-08-10 05:20:40 -0400 |
| commit | a9810c2281a2c4fc2265aa8c59fa9bf101e3a3b5 (patch) | |
| tree | a9afaee0d6514505ccd35343bca8bb931a196f76 /ir.c | |
| parent | c9980711ce42de9cf58db35f41ce1ac42bfea0c7 (diff) | |
better error reporting around uninitialized values
Diffstat (limited to 'ir.c')
| -rw-r--r-- | ir.c | 40 |
1 files changed, 3 insertions, 37 deletions
@@ -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); -} |
