cgen: fix struct init 0 fields & tests

pull/4107/head
Joe Conigliaro 2020-03-23 21:57:54 +11:00
parent e13bbd8c40
commit 80676cf44f
4 changed files with 11 additions and 7 deletions

View File

@ -1587,7 +1587,7 @@ fn (g mut Gen) struct_init(it ast.StructInit) {
g.writeln('\t.$field_name = $zero,') // zer0')
}
}
if it.fields.len == 0 {
if it.fields.len == 0 && info.fields.len == 0 {
g.write('0')
}
g.write('}')

View File

@ -65,7 +65,7 @@ int main(int argc, char** argv) {
int g = ((int)(3.0));
byte* bytes = ((byte*)(0));
User* user_ptr = (User*)memdup(&(User){ .age = 0,
0}, sizeof(User));
}, sizeof(User));
return 0;
}
@ -88,7 +88,8 @@ i < 10; i++) {
});
array_User users = new_array_from_c_array(1, 1, sizeof(User), (User[]){
(User){
0},
.age = 0,
},
});
bool b = (*(bool*)array_get(bools, 0));
array_string mystrings = new_array_from_c_array(2, 2, sizeof(string), (string[]){

View File

@ -30,7 +30,8 @@ void init_user() {
User get_user() {
User user = (User){
0};
.name = tos3(""),
};
return user;
}

View File

@ -66,7 +66,9 @@ int main(int argc, char** argv) {
_vinit();
os__args = os__init_os_args(argc, (byteptr*)argv);
User user = (User){
0};
.age = 0,
.name = tos3(""),
};
user.age = 10;
user.age++;
user.name = tos3("bob");