From e13bbd8c40bc0168c9bf85e245480ecc93f3d123 Mon Sep 17 00:00:00 2001 From: Joe Conigliaro Date: Mon, 23 Mar 2020 21:17:14 +1100 Subject: [PATCH] cgen: map init struct fields & fn type arg fix --- vlib/v/gen/cgen.v | 21 ++++++++++++++++----- 1 file changed, 16 insertions(+), 5 deletions(-) diff --git a/vlib/v/gen/cgen.v b/vlib/v/gen/cgen.v index a8f4267a8c..19c9198c55 100644 --- a/vlib/v/gen/cgen.v +++ b/vlib/v/gen/cgen.v @@ -656,11 +656,17 @@ fn (g mut Gen) fn_args(args []table.Arg, is_variadic bool) { if arg_type_sym.kind == .function { info := arg_type_sym.info as table.FnType func := info.func - g.write('${g.typ(func.return_type)} (*$arg.name)(') - g.definitions.write('${g.typ(func.return_type)} (*$arg.name)(') - g.fn_args(func.args, func.is_variadic) - g.write(')') - g.definitions.write(')') + if !info.is_anon { + g.write(arg_type_name + ' ' + arg.name) + g.definitions.write(arg_type_name + ' ' + arg.name) + } + else { + g.write('${g.typ(func.return_type)} (*$arg.name)(') + g.definitions.write('${g.typ(func.return_type)} (*$arg.name)(') + g.fn_args(func.args, func.is_variadic) + g.write(')') + g.definitions.write(')') + } } else if no_names { g.write(arg_type_name) @@ -2099,6 +2105,11 @@ fn (g &Gen) type_default(typ table.Type) string { elem_type := 'int' return 'new_array(0, 1, sizeof($elem_type))' } + if sym.kind == .map { + value_sym := g.table.get_type_symbol(sym.map_info().value_type) + value_typ_str := value_sym.name.replace('.', '__') + return 'new_map(1, sizeof($value_typ_str))' + } // Always set pointers to 0 if table.type_is_ptr(typ) { return '0'