From 332d52f459b1088dbc240d22e1d3d1cf97a10e2f Mon Sep 17 00:00:00 2001 From: Kris Cherven <50562493+krischerven@users.noreply.github.com> Date: Thu, 16 Apr 2020 01:28:41 -0400 Subject: [PATCH] fmt: stop mangling reference names --- vlib/v/fmt/fmt.v | 8 +++++++- vlib/v/fmt/tests/type_ptr_keep.vv | 14 ++++++++++++++ 2 files changed, 21 insertions(+), 1 deletion(-) create mode 100644 vlib/v/fmt/tests/type_ptr_keep.vv 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 { +}