diff --git a/vlib/v/gen/c/auto_str_methods.v b/vlib/v/gen/c/auto_str_methods.v index 95d4c86272..cb7dce4ae6 100644 --- a/vlib/v/gen/c/auto_str_methods.v +++ b/vlib/v/gen/c/auto_str_methods.v @@ -45,8 +45,7 @@ fn (g &Gen) type_to_fmt(typ table.Type) string { if typ.is_ptr() && (typ.is_int() || typ.is_float()) { return '%.*s\\000' } else if sym.kind in [.struct_, .array, .array_fixed, .map, .bool, .enum_, .interface_, .sum_type, - .function, - ] { + .function, .alias] { return '%.*s\\000' } else if sym.kind == .string { return "'%.*s\\000'" diff --git a/vlib/v/tests/alias_in_a_struct_field_autostr_test.v b/vlib/v/tests/alias_in_a_struct_field_autostr_test.v new file mode 100644 index 0000000000..fad01f6984 --- /dev/null +++ b/vlib/v/tests/alias_in_a_struct_field_autostr_test.v @@ -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}' +}