From d55f4ab097729c28dc9722e91e04d05f58450c3d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Daniel=20D=C3=A4schle?= Date: Sun, 12 Apr 2020 15:25:02 +0200 Subject: [PATCH] cgen: fix error priting struct which has .str already --- vlib/v/gen/cgen.v | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/vlib/v/gen/cgen.v b/vlib/v/gen/cgen.v index 6238774774..92a9a83203 100644 --- a/vlib/v/gen/cgen.v +++ b/vlib/v/gen/cgen.v @@ -3207,7 +3207,8 @@ fn (g mut Gen) gen_str_for_struct(info table.Struct, styp string) { sym := g.table.get_type_symbol(field.typ) if sym.kind == .struct_ { field_styp := g.typ(field.typ) - g.definitions.write('indents.len, indents.str, ${field_styp}_str(it.$field.name, indent_count + 1).len, ${field_styp}_str(it.$field.name, indent_count + 1).str') + second_str_param := if sym.has_method('str') { '' } else { ', indent_count + 1' } + g.definitions.write('indents.len, indents.str, ${field_styp}_str(it.$field.name$second_str_param).len, ${field_styp}_str(it.$field.name$second_str_param).str') } else { g.definitions.write('indents.len, indents.str, it.$field.name') if field.typ == table.string_type { @@ -3215,9 +3216,9 @@ fn (g mut Gen) gen_str_for_struct(info table.Struct, styp string) { } else if field.typ == table.bool_type { g.definitions.write(' ? 4 : 5, it.${field.name} ? "true" : "false"') } - if i < info.fields.len - 1 { - g.definitions.write(', ') - } + } + if i < info.fields.len - 1 { + g.definitions.write(', ') } } }