harec

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

commit 20eabcb853dcf2ee6b192599c68002b5560f7296
parent e9d0f70132fe77b9dceede5008ff6807632e0825
Author: Pierre Curto <pierre.curto@gmail.com>
Date:   Wed,  9 Nov 2022 13:58:26 +0100

harec: fix indexing of void slice

Fixes: https://todo.sr.ht/~sircmpwn/hare/772

Signed-off-by: Pierre Curto <pierre.curto@gmail.com>

Diffstat:
Msrc/check.c | 6++++++
Mtests/08-slices.ha | 3+++
2 files changed, 9 insertions(+), 0 deletions(-)

diff --git a/src/check.c b/src/check.c @@ -206,6 +206,12 @@ check_expr_access(struct context *ctx, type_storage_unparse(atype->storage)); return; } + if (atype->storage == STORAGE_SLICE + && atype->array.members->storage == STORAGE_VOID) { + error(ctx, aexpr->access.array->loc, expr, + "Cannot use index into slice of void"); + return; + } if (!type_is_integer(itype)) { error(ctx, aexpr->access.index->loc, expr, "Cannot use non-integer %s type as slice/array index", diff --git a/tests/08-slices.ha b/tests/08-slices.ha @@ -61,6 +61,9 @@ fn indexing() void = { assert(compile( "fn test() void = { let x = 10; x[10]; };" ) as exited != EXIT_SUCCESS); + assert(compile( + "fn test() void = { let s: []u8 = []; let ss = s: []void; ss[0] = ss[1]; };" + ) as exited != EXIT_SUCCESS); }; fn zero3(s: []int) void = {