From 4aedef367c2e519aa88a95c3108a29897c5a92e3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Daniel=20D=C3=A4schle?= Date: Tue, 7 Apr 2020 17:52:15 +0200 Subject: [PATCH] cgen: print bool and string correctly in struct --- .editorconfig | 3 +++ vlib/v/gen/cgen.v | 4 ++++ vlib/v/tests/prod/assoc.prod.v.expected.txt | 2 +- 3 files changed, 8 insertions(+), 1 deletion(-) diff --git a/.editorconfig b/.editorconfig index f49fdd1b6b..26d7ca8bba 100644 --- a/.editorconfig +++ b/.editorconfig @@ -17,5 +17,8 @@ indent_size = 2 [*.md] trim_trailing_whitespace = false +[*.txt] +insert_final_newline = false + [Makefile] indent_style = tab diff --git a/vlib/v/gen/cgen.v b/vlib/v/gen/cgen.v index 7ada2d9991..af741e3569 100644 --- a/vlib/v/gen/cgen.v +++ b/vlib/v/gen/cgen.v @@ -2952,6 +2952,8 @@ fn (g mut Gen) gen_str_for_type(sym table.TypeSymbol, styp string) { g.definitions.write('a.' + field.name) if field.typ == table.string_type { g.definitions.write('.len, a.${field.name}.str') + } else if field.typ == table.bool_type { + g.definitions.write(' == true ? 4 : 5, a.${field.name} == true ? "true" : "false"') } if i < info.fields.len - 1 { g.definitions.write(', ') @@ -2963,6 +2965,8 @@ fn (g mut Gen) gen_str_for_type(sym table.TypeSymbol, styp string) { fn type_to_fmt(typ table.Type) string { n := int(typ) if n == table.string_type { + return '\'%.*s\'' + } else if n == table.bool_type { return '%.*s' } return '%d' diff --git a/vlib/v/tests/prod/assoc.prod.v.expected.txt b/vlib/v/tests/prod/assoc.prod.v.expected.txt index d69f916aa1..0a0ead9519 100644 --- a/vlib/v/tests/prod/assoc.prod.v.expected.txt +++ b/vlib/v/tests/prod/assoc.prod.v.expected.txt @@ -1,3 +1,3 @@ MyStruct { - s: 6 + s: '6' } \ No newline at end of file