harec

[hare] Hare compiler, written in C11 for POSIX OSs
Log | Files | Refs | README | LICENSE

commit 658c7a4d9ada2f40fef246f91e9609e189c17da6
parent 904a631e6d7ca10ef820c136afe496f1a4b6b8eb
Author: Ember Sawady <ecs@d2evs.net>
Date:   Tue, 31 Jan 2023 22:28:31 +0000

Don't crash on global without type or initializer

Signed-off-by: Ember Sawady <ecs@d2evs.net>

Diffstat:
Msrc/check.c | 2++
Mtests/26-regression.ha | 2++
2 files changed, 4 insertions(+), 0 deletions(-)

diff --git a/src/check.c b/src/check.c @@ -3770,6 +3770,8 @@ resolve_global(struct context *ctx, struct incomplete_declaration *idecl) // the type is set by the expression struct expression *initializer = xcalloc(1, sizeof(struct expression)); + expect(ctx, &idecl->decl.loc, decl->init, + "Cannot infer type without an initializer"); check_expression(ctx, decl->init, initializer, type); type = lower_const(initializer->result, NULL); assert(type); diff --git a/tests/26-regression.ha b/tests/26-regression.ha @@ -81,4 +81,6 @@ export fn main() void = { case &c => void; };" ) as rt::exited != rt::EXIT_SUCCESS); + + assert(rt::compile("let a;") as rt::exited != rt::EXIT_SUCCESS); };