commit 675113c99f6680e6905b58f7e413c225e07f11fc
parent 3f492a587d81ac0c6f4e081176d9ff75d884dfe2
Author: Bor Grošelj Simić <bgs@turminal.net>
Date: Sat, 19 Nov 2022 23:04:27 +0100
prohibit unbounded arrays of values of undefined size
Signed-off-by: Bor Grošelj Simić <bgs@turminal.net>
Diffstat:
2 files changed, 12 insertions(+), 3 deletions(-)
diff --git a/src/type_store.c b/src/type_store.c
@@ -746,7 +746,7 @@ type_init_from_atype(struct type_store *store,
*type = builtin_type_void;
return (struct dimensions){0};
}
- if (type->array.length != SIZE_UNDEFINED && memb.size == SIZE_UNDEFINED) {
+ if (memb.size == SIZE_UNDEFINED) {
error(store->check_context, atype->loc,
"Type of undefined size is not a valid array member");
*type = builtin_type_void;
@@ -1004,7 +1004,7 @@ type_store_lookup_array(struct type_store *store, struct location loc,
"Type of size 0 is not a valid array member");
return &builtin_type_void;
}
- if (len != SIZE_UNDEFINED && members->size == SIZE_UNDEFINED) {
+ if (members->size == SIZE_UNDEFINED) {
error(store->check_context, loc,
"Type of undefined size is not a valid member of a bounded array");
return &builtin_type_void;
diff --git a/tests/01-arrays.ha b/tests/01-arrays.ha
@@ -1,4 +1,4 @@
-use rt::{compile, exited, EXIT_SUCCESS};
+use rt::{compile, exited, EXIT_SUCCESS, EXIT_FAILURE};
fn indexing() void = {
let x = [1, 2, 3];
@@ -133,6 +133,14 @@ fn eval_access() void = {
static assert([1, 2][0] == 1 && [1, 2][1] == 2);
};
+fn reject() void = {
+ // unbounded arrays of values of undefined size
+ assert(compile("fn f() void = { let x = null: *[*][*]int; };")
+ as exited == EXIT_FAILURE);
+ assert(compile("fn f() void = { let x = null: *[*]fn ()int; };")
+ as exited == EXIT_FAILURE);
+};
+
export fn main() void = {
indexing();
measurements();
@@ -145,4 +153,5 @@ export fn main() void = {
extype();
eval_array();
eval_access();
+ reject();
};