From 5eee980499c4e320165bf78ffa269c868027684d Mon Sep 17 00:00:00 2001 From: Joe Conigliaro Date: Wed, 14 Aug 2019 19:35:51 +1000 Subject: [PATCH] auto init struct map fields --- compiler/parser.v | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/compiler/parser.v b/compiler/parser.v index 624f05e7f4..36b1b6d316 100644 --- a/compiler/parser.v +++ b/compiler/parser.v @@ -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') { 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) if def_val != '' && def_val != 'STRUCT_DEFAULT_VALUE' { p.gen('.$field.name = $def_val')