diff --git a/vlib/v/fmt/fmt.v b/vlib/v/fmt/fmt.v index bcb72c57e5..37e9d75638 100644 --- a/vlib/v/fmt/fmt.v +++ b/vlib/v/fmt/fmt.v @@ -453,7 +453,13 @@ fn (f mut Fmt) struct_decl(node ast.StructDecl) { } fn (f &Fmt) type_to_str(t table.Type) string { - res := f.table.type_to_str(t) + mut res := f.table.type_to_str(t) + // type_ptr => &type + if res.ends_with('_ptr') { + res = res[0 .. res.len-4] + start_pos := 2 * res.count('[]') + res = res[0 .. start_pos] + '&' + res[start_pos .. res.len] + } return res.replace(f.cur_mod + '.', '') } diff --git a/vlib/v/fmt/tests/type_ptr_keep.vv b/vlib/v/fmt/tests/type_ptr_keep.vv new file mode 100644 index 0000000000..d54911c24d --- /dev/null +++ b/vlib/v/fmt/tests/type_ptr_keep.vv @@ -0,0 +1,14 @@ +const ( + x = &Test{} + y = []&Test + z = &[]&Test +) + +fn test_type_ptr() { + a := &Test{} + b := []&Test + c := &[]&Test +} + +struct Test { +}