harec

Unnamed repository; edit this file 'description' to name the repository.
Log | Files | Refs | README | LICENSE

commit d00404b47d1b5302b5f02554eb5cd528ec2309c8
parent 285c36301efa3a83f3af2a8bd4340eaa4ced95f6
Author: Sebastian <sebastian@sebsite.pw>
Date:   Fri, 11 Mar 2022 18:41:42 -0500

check: use dereferenced type when checking len

Reproduction of bug:

$ cat > t.ha <<'EOF'
use fmt;

export fn main() void = {
	let t: []int = [1, 2, 3];
	let t = t: *[*]int;
	fmt::println(len(t))!;
};
EOF
$ hare build t.ha
Assertion failed: len != SIZE_UNDEFINED (src/gen.c: gen_expr_measure: 2415)
Error: harec: exited with signal 6
hare build: build failed

This was caused by an incorrect check for a defined length, which is
fixed by this commit.

$ hare build t.ha
Error /var/tmp/t.ha:6:27: Cannot take length of array type with undefined length
Error: harec: exited with status 1
hare build: build failed

Signed-off-by: Sebastian <sebastian@sebsite.pw>

Diffstat:
Msrc/check.c | 2+-
1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/src/check.c b/src/check.c @@ -1889,7 +1889,7 @@ check_expr_measure(struct context *ctx, "len argument must be of an array, slice, or str type"); return; } - if (expr->measure.value->result->size == SIZE_UNDEFINED) { + if (atype->size == SIZE_UNDEFINED) { error(ctx, aexpr->measure.value->loc, expr, "Cannot take length of array type with undefined length"); return;