mirror of
https://github.com/vlang/v.git
synced 2023-08-10 21:13:21 +03:00
auto init struct map fields
This commit is contained in:
parent
772c0c3f93
commit
5eee980499
@ -2822,6 +2822,16 @@ fn (p mut Parser) struct_init(typ string, is_c_struct_init bool) string {
|
|||||||
if !p.builtin_mod && field_typ.ends_with('*') && field_typ.contains('Cfg') {
|
if !p.builtin_mod && field_typ.ends_with('*') && field_typ.contains('Cfg') {
|
||||||
p.error('pointer field `${typ}.${field.name}` must be initialized')
|
p.error('pointer field `${typ}.${field.name}` must be initialized')
|
||||||
}
|
}
|
||||||
|
// init map fields
|
||||||
|
if field_typ.starts_with('map_') {
|
||||||
|
p.gen('.$field.name = new_map(1, sizeof( ${field_typ.right(4)} ))')
|
||||||
|
inited_fields << field.name
|
||||||
|
if i != t.fields.len - 1 {
|
||||||
|
p.gen(',')
|
||||||
|
}
|
||||||
|
did_gen_something = true
|
||||||
|
continue
|
||||||
|
}
|
||||||
def_val := type_default(field_typ)
|
def_val := type_default(field_typ)
|
||||||
if def_val != '' && def_val != 'STRUCT_DEFAULT_VALUE' {
|
if def_val != '' && def_val != 'STRUCT_DEFAULT_VALUE' {
|
||||||
p.gen('.$field.name = $def_val')
|
p.gen('.$field.name = $def_val')
|
||||||
|
Loading…
Reference in New Issue
Block a user