harec

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

commit f2496cde69520e29dd256bd94f295d2c4ad843ef
parent 942f4bd9e7ea2623c54ab57b602f9f210a0b1bb4
Author: Ember Sawady <ecs@d2evs.net>
Date:   Mon,  6 Feb 2023 16:34:30 +0000

eval: check eval result for array constant members

Ditto for tuples

Fixes: https://todo.sr.ht/~sircmpwn/hare/778
Signed-off-by: Ember Sawady <ecs@d2evs.net>

Diffstat:
Msrc/eval.c | 12++++++++++--
Mtests/26-regression.ha | 1+
2 files changed, 11 insertions(+), 2 deletions(-)

diff --git a/src/eval.c b/src/eval.c @@ -419,7 +419,11 @@ eval_const(struct context *ctx, struct expression *in, struct expression *out) struct array_constant *aconst = *anext = xcalloc(sizeof(struct array_constant), 1); aconst->value = xcalloc(sizeof(struct expression), 1); - eval_expr(ctx, arr->value, aconst->value); + enum eval_result r = + eval_expr(ctx, arr->value, aconst->value); + if (r != EVAL_OK) { + return r; + } anext = &aconst->next; } break; @@ -449,7 +453,11 @@ eval_const(struct context *ctx, struct expression *in, struct expression *out) xcalloc(1, sizeof(struct tuple_constant)); tconst->field = tuple->field; tconst->value = xcalloc(1, sizeof(struct expression)); - eval_expr(ctx, tuple->value, tconst->value); + enum eval_result r = + eval_expr(ctx, tuple->value, tconst->value); + if (r != EVAL_OK) { + return r; + } tnext = &tconst->next; } break; diff --git a/tests/26-regression.ha b/tests/26-regression.ha @@ -113,4 +113,5 @@ export fn main() void = { assert(rt::compile("fn a() []int = alloc([]: [*]int, 0);") as rt::exited != rt::EXIT_SUCCESS); assert(rt::compile("fn a() [1]int = [1]: []int: [1]int;") as rt::exited != rt::EXIT_SUCCESS); assert(rt::compile("fn a() void = &*&a;") as rt::exited != rt::EXIT_SUCCESS); + assert(rt::compile("let a = [*&0];") as rt::exited != rt::EXIT_SUCCESS); };