From 38587347c4b88eed5789483ede3a9d38e7f11bf9 Mon Sep 17 00:00:00 2001 From: =?utf8?q?J=C3=A9r=C3=A9mie=20Astor?= Date: Sun, 3 Jan 2021 01:02:26 +0100 Subject: [PATCH] :art: Array safety for abstract types --- src/parse/scan1.c | 4 ++++ tests/error/abstract_array.gw | 2 ++ 2 files changed, 6 insertions(+) create mode 100644 tests/error/abstract_array.gw diff --git a/src/parse/scan1.c b/src/parse/scan1.c index c1a7ce6e..a5766604 100644 --- a/src/parse/scan1.c +++ b/src/parse/scan1.c @@ -86,6 +86,10 @@ ANN static m_bool scan1_decl(const Env env, const Exp_Decl* decl) { CHECK_BB(scan1_exp(env, var->array->exp)) t = array_type(env, decl->type, var->array->depth); } + if(t->array_depth && GET_FLAG(array_base(t), abstract) && ((var->array && var->array->exp) + || (decl->td->array && decl->td->array->exp))) + ERR_B(var->pos, _("arrays of abstract type '%s' must be declared empty"), + array_base(t)->name); const Value v = var->value = var->value ?: new_value(env->gwion->mp, t, s_name(var->xid)); nspc_add_value(env->curr, var->xid, v); if(GET_FLAG(t, abstract) && !GET_FLAG(decl->td, late)) diff --git a/tests/error/abstract_array.gw b/tests/error/abstract_array.gw new file mode 100644 index 00000000..d89b9016 --- /dev/null +++ b/tests/error/abstract_array.gw @@ -0,0 +1,2 @@ +#! [contains] must be declared empty +var Shred[12] shreds; -- 2.43.0