]> ocean-lang.org Git - ocean/commitdiff
oceani: implement struct field initialisation properly.
authorNeilBrown <neil@brown.name>
Sat, 16 Oct 2021 05:09:59 +0000 (16:09 +1100)
committerNeilBrown <neil@brown.name>
Sat, 30 Oct 2021 22:18:36 +0000 (09:18 +1100)
I wasn't testing default initial values for struct fields, so of course
it didn't work.

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

index e7e9f22486df6bdac410d996b2d7de05f7bd4e1b..d5541e9c3e21ea27ddb418d666789d8062c60beb 100644 (file)
@@ -555,7 +555,7 @@ Time to test if structure declarations and accesses work correctly.
        struct foo
                size:[three]number
                name:string
        struct foo
                size:[three]number
                name:string
-               active:Boolean
+               active:Boolean = True
 
        struct baz { a:number; b:Boolean; }
 
 
        struct baz { a:number; b:Boolean; }
 
@@ -571,7 +571,8 @@ Time to test if structure declarations and accesses work correctly.
 
                        info[i].name = nm
                        info[i].size[0] = i*i
 
                        info[i].name = nm
                        info[i].size[0] = i*i
-                       info[i].active = nm == "jane"
+                       if nm != "jane":
+                               info[i].active = False
 
                for i:=0; then i=i+1; while i < 4:
                        print info[i].name, info[i].active, info[i].size[0]
 
                for i:=0; then i=i+1; while i < 4:
                        print info[i].name, info[i].active, info[i].size[0]
index 18e593065705ea6324a6ddf68250142df4ec3d72..416084e26512c613ec287d70feaa85a8ad65e0e6 100644 (file)
@@ -1758,7 +1758,12 @@ function will be needed.
                for (i = 0; i < type->structure.nfields; i++) {
                        struct value *v;
                        v = (void*) val->ptr + type->structure.fields[i].offset;
                for (i = 0; i < type->structure.nfields; i++) {
                        struct value *v;
                        v = (void*) val->ptr + type->structure.fields[i].offset;
-                       val_init(type->structure.fields[i].type, v);
+                       if (type->structure.fields[i].init)
+                               dup_value(type->structure.fields[i].type, 
+                                         type->structure.fields[i].init,
+                                         v);
+                       else
+                               val_init(type->structure.fields[i].type, v);
                }
        }
 
                }
        }