mirror of
https://github.com/vlang/v.git
synced 2023-08-10 21:13:21 +03:00
cgen: make .alias fields in structs use their proper string format, instead of the default %d (#9197)
This commit is contained in:
parent
2ed73bf243
commit
b893373e63
@ -45,8 +45,7 @@ fn (g &Gen) type_to_fmt(typ table.Type) string {
|
|||||||
if typ.is_ptr() && (typ.is_int() || typ.is_float()) {
|
if typ.is_ptr() && (typ.is_int() || typ.is_float()) {
|
||||||
return '%.*s\\000'
|
return '%.*s\\000'
|
||||||
} else if sym.kind in [.struct_, .array, .array_fixed, .map, .bool, .enum_, .interface_, .sum_type,
|
} else if sym.kind in [.struct_, .array, .array_fixed, .map, .bool, .enum_, .interface_, .sum_type,
|
||||||
.function,
|
.function, .alias] {
|
||||||
] {
|
|
||||||
return '%.*s\\000'
|
return '%.*s\\000'
|
||||||
} else if sym.kind == .string {
|
} else if sym.kind == .string {
|
||||||
return "'%.*s\\000'"
|
return "'%.*s\\000'"
|
||||||
|
12
vlib/v/tests/alias_in_a_struct_field_autostr_test.v
Normal file
12
vlib/v/tests/alias_in_a_struct_field_autostr_test.v
Normal file
@ -0,0 +1,12 @@
|
|||||||
|
type Duration = i64
|
||||||
|
|
||||||
|
struct Abc {
|
||||||
|
d Duration
|
||||||
|
}
|
||||||
|
|
||||||
|
fn test_string_interpolation_of_alias() {
|
||||||
|
x := Abc{
|
||||||
|
d: i64(9_123_456_789)
|
||||||
|
}
|
||||||
|
assert '$x' == 'Abc{\n d: Duration(9123456789)\n}'
|
||||||
|
}
|
Loading…
Reference in New Issue
Block a user