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