]> ocean-lang.org Git - ocean/commitdiff
oceani: move ->prepare_type call (back) into val_alloc()
authorNeilBrown <neil@brown.name>
Thu, 14 Oct 2021 02:59:34 +0000 (13:59 +1100)
committerNeilBrown <neil@brown.name>
Sat, 30 Oct 2021 22:18:36 +0000 (09:18 +1100)
This ensures it is called for struct fields as well.

Signed-off-by: NeilBrown <neil@brown.name>
csrc/oceani-tests.mdc
csrc/oceani.mdc

index 46c1a09530a8c640057529e0668fa8422a3fa01d..e7e9f22486df6bdac410d996b2d7de05f7bd4e1b 100644 (file)
@@ -551,8 +551,9 @@ Time to test if structure declarations and accesses work correctly.
 
 ###### test: structs
 
+       const three ::= 3
        struct foo
-               size:[3]number
+               size:[three]number
                name:string
                active:Boolean
 
index 7ff26c5f7aac1871ac03b9e1fa2fd79aa9c37bd2..18e593065705ea6324a6ddf68250142df4ec3d72 100644 (file)
@@ -537,6 +537,9 @@ Named type are stored in a simple linked list.  Objects of each type are
        {
                struct value *ret;
 
+               if (t->prepare_type)
+                       t->prepare_type(t);
+
                ret = calloc(1, t->size);
                if (init)
                        memcpy(ret, init, t->size);
@@ -3366,9 +3369,6 @@ it is declared, and error will be raised as the name is created as
                        v = v->merged;
                free_value(v->type, v->val);
                free(v->val);
-               if (v->type->prepare_type)
-                       // FIXME is this the first usage of the type?
-                       v->type->prepare_type(v->type);
                if (b->right) {
                        right = interp_exec(b->right, &rtype);
                        v->val = val_alloc(v->type, &right);