1
0
mirror of https://github.com/vlang/v.git synced 2023-08-10 21:13:21 +03:00

cgen: print bool correctly in interpolation

This commit is contained in:
Daniel Däschle 2020-04-07 23:26:20 +02:00 committed by GitHub
parent 582ee9e643
commit 59ac0bd46b
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -2236,7 +2236,7 @@ fn (g mut Gen) string_inter_literal(node ast.StringInterLiteral) {
verror('only V strings can be formatted with a ${sfmt} format')
}
g.write('%' + sfmt[1..])
} else if node.expr_types[i] == table.string_type {
} else if node.expr_types[i] == table.string_type || node.expr_types[i] == table.bool_type {
g.write('%.*s')
} else {
g.write('%d')
@ -2260,6 +2260,11 @@ fn (g mut Gen) string_inter_literal(node ast.StringInterLiteral) {
g.write('.len, ')
g.expr(expr)
g.write('.str')
} else if node.expr_types[i] == table.bool_type {
g.expr(expr)
g.write(' ? 4 : 5, ')
g.expr(expr)
g.write(' ? "true" : "false"')
} else {
g.expr(expr)
}
@ -2949,7 +2954,7 @@ fn (g mut Gen) gen_str_for_type(sym table.TypeSymbol, styp string) {
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"')
g.definitions.write(' ? 4 : 5, a.${field.name} ? "true" : "false"')
}
if i < info.fields.len - 1 {
g.definitions.write(', ')