]> Nishi Git Mirror - gwion.git/commitdiff
:art: Array safety for abstract types
authorJérémie Astor <fennecdjay@gmail.com>
Sun, 3 Jan 2021 00:02:26 +0000 (01:02 +0100)
committerJérémie Astor <fennecdjay@gmail.com>
Sun, 3 Jan 2021 00:02:26 +0000 (01:02 +0100)
src/parse/scan1.c
tests/error/abstract_array.gw [new file with mode: 0644]

index c1a7ce6e4cb73de640bc473f99858090febccb20..a5766604be574789551bf80bdb75bab382e80b94 100644 (file)
@@ -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 (file)
index 0000000..d89b901
--- /dev/null
@@ -0,0 +1,2 @@
+#! [contains] must be declared empty
+var Shred[12] shreds;