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.
Breaking-Change: language
References: https://todo.sr.ht/~sircmpwn/hare/809
Signed-off-by: Bor Grošelj Simić <bgs@turminal.net>
---
src/check.c | 12 +-----------
tests/19-append.ha | 4 ++--
tests/28-insert.ha | 4 ++--
3 files changed, 5 insertions(+), 15 deletions(-)
diff --git a/src/check.c b/src/check.c
index dd91dd88..32b67e69 100644
--- a/src/check.c
+++ b/src/check.c
@@ -722,10 +722,7 @@ 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",
exprtype_name);
@@ -734,13 +731,6 @@ check_expr_append_insert(struct context *ctx,
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
hi,
On Fri, Jan 17, 2025 at 04:00:29AM +0100, Bor Grošelj Simić wrote:
> 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.
>
> Breaking-Change: language
> References: https://todo.sr.ht/~sircmpwn/hare/809
> Signed-off-by: Bor Grošelj Simić <bgs@turminal.net>
> ---
> src/check.c | 12 +-----------
> tests/19-append.ha | 4 ++--
> tests/28-insert.ha | 4 ++--
> 3 files changed, 5 insertions(+), 15 deletions(-)
>
> diff --git a/src/check.c b/src/check.c
> index dd91dd88..32b67e69 100644
> --- a/src/check.c
> +++ b/src/check.c
> @@ -722,10 +722,7 @@ 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",
i think you have to update the error message here to not not include
"array pointer".