~sircmpwn/hare-dev

This thread contains a patchset. You're looking at the original emails, but you may wish to use the patch review UI. Review patch
1

[PATCH harec v2] check: don't autodereference append/insert value

Details
Message ID
<20250118073542.26382-3-bgs@turminal.net>
Sender timestamp
1737189293
DKIM signature
pass
Download raw message
Patch: +6 -16
Initial support for this (only in check) was introduced 3 years ago. Then
someone reported this aborts in gen, tracked as #809. Some time later we
fixed that, but really this should not have been introduced in the first
place.

Does not need a spec change because the spec doesn't say anything about
append/insert values at the moment.

Breaking-Change: language
References: https://todo.sr.ht/~sircmpwn/hare/809
Signed-off-by: Bor Grošelj Simić <bgs@turminal.net>
---
v1 -> v2:
drop mention of pointers from an error message as suggested by Lorenz

 src/check.c        | 14 ++------------
 tests/19-append.ha |  4 ++--
 tests/28-insert.ha |  4 ++--
 3 files changed, 6 insertions(+), 16 deletions(-)

diff --git a/src/check.c b/src/check.c
index dd91dd88..70a6e546 100644
--- a/src/check.c
+++ b/src/check.c
@@ -722,25 +722,15 @@ check_expr_append_insert(struct context *ctx,
		len = lower_implicit_cast(ctx, &builtin_type_size, len);
		expr->append.length = len;
	} else if (valtype->storage != STORAGE_SLICE
			&& valtype->storage != STORAGE_ARRAY
			&& (valtype->storage != STORAGE_POINTER
				|| valtype->pointer.referent->storage != STORAGE_ARRAY
				|| valtype->pointer.nullable)) {
			&& valtype->storage != STORAGE_ARRAY) {
		error(ctx, aexpr->append.value->loc, expr,
			"Value must be an array, slice, or array pointer in multi-valued %s",
			"Value must be an array or a slice in multi-valued %s",
			exprtype_name);
		return;
	} else if (valtype->size == SIZE_UNDEFINED) {
		error(ctx, aexpr->loc, expr, "Value array must be bounded");
		return;
	}
	if (valtype->storage == STORAGE_POINTER) {
		valtype = valtype->pointer.referent;
		const struct type *slice = type_store_lookup_slice(ctx,
			aexpr->loc, valtype->array.members);
		expr->append.value = lower_implicit_cast(ctx,
			slice, expr->append.value);
	}
	if (sltype->array.members != valtype->array.members) {
		error(ctx, aexpr->loc, expr,
			"Value member type must match object member type");
diff --git a/tests/19-append.ha b/tests/19-append.ha
index 7f211c7b..f035b989 100644
--- a/tests/19-append.ha
+++ b/tests/19-append.ha
@@ -27,7 +27,7 @@ fn multi() void = {
	free(x);

	let x: []int = alloc([], 3)!;
	append(x, &[1, 2, 3]...)!;
	append(x, [1, 2, 3]...)!;
	assert(len(x) == 3);
	free(x);
};
@@ -49,7 +49,7 @@ fn _static() void = {
	};

	let x = [1, 2, 3][..0];
	static append(x, &[1, 2, 3]...)!;
	static append(x, [1, 2, 3]...)!;
	assert(len(x) == 3);
};

diff --git a/tests/28-insert.ha b/tests/28-insert.ha
index 7de388eb..219f55c5 100644
--- a/tests/28-insert.ha
+++ b/tests/28-insert.ha
@@ -34,7 +34,7 @@ fn multi() void = {
	free(x);

	let x: []int = alloc([], 3)!;
	insert(x[0], &[1, 2, 3]...)!;
	insert(x[0], [1, 2, 3]...)!;
	assert(len(x) == 3);
	free(x);
};
@@ -57,7 +57,7 @@ fn _static() void = {
	};

	let x = [1, 2, 3][..0];
	static insert(x[0], &[1, 2, 3]...)!;
	static insert(x[0], [1, 2, 3]...)!;
	assert(len(x) == 3);
};

-- 
2.47.1
Details
Message ID
<D78SQ0KZ9XFX.R5B864HZXZRG@d2evs.net>
In-Reply-To
<20250118073542.26382-3-bgs@turminal.net> (view parent)
Sender timestamp
1737568768
DKIM signature
pass
Download raw message
thanks!

to git@git.sr.ht:~sircmpwn/harec
  d1f1151..0b339b3  master -> master
Reply to thread Export thread (mbox)