From 1028f0b59e72799683ef72994c6dda0da5fb1f10 Mon Sep 17 00:00:00 2001 From: yuyi Date: Thu, 23 Dec 2021 01:11:09 +0800 Subject: [PATCH] fmt: fix error of generic struct_init using module (fix #12893) (#12935) --- vlib/js/js.js.v | 2 +- vlib/v/fmt/fmt.v | 2 +- vlib/v/fmt/tests/generic_structs_keep.vv | 2 +- vlib/v/fmt/tests/generic_structs_using_mod_keep.vv | 8 ++++++++ vlib/v/fmt/tests/obj/obj.v | 3 +++ vlib/v/tests/generics_test.v | 8 ++++---- vlib/v/tests/str_gen_test.v | 2 +- 7 files changed, 19 insertions(+), 8 deletions(-) create mode 100644 vlib/v/fmt/tests/generic_structs_using_mod_keep.vv create mode 100644 vlib/v/fmt/tests/obj/obj.v diff --git a/vlib/js/js.js.v b/vlib/js/js.js.v index c7e429648c..6fe2774514 100644 --- a/vlib/js/js.js.v +++ b/vlib/js/js.js.v @@ -24,7 +24,7 @@ pub interface JS.Response { pub fn fetch(input string, init map[string]JS.Any) promise.Promise { p_init := JS.Any(voidptr(0)) - p := promise.Promise{p_init} + p := promise.Promise{p_init} #let obj = {}; for (let [key,val] of init.map) { obj[key] = val; } #p.promise = fetch(input.str,obj); diff --git a/vlib/v/fmt/fmt.v b/vlib/v/fmt/fmt.v index d613e35c9d..65298041a5 100644 --- a/vlib/v/fmt/fmt.v +++ b/vlib/v/fmt/fmt.v @@ -213,7 +213,7 @@ pub fn (mut f Fmt) short_module(name string) string { generic_levels := name.trim_suffix('>').split('<') mut res := '${f.short_module(generic_levels[0])}' for i in 1 .. generic_levels.len { - genshorts := generic_levels[i].split(',').map(f.short_module(it)).join(',') + genshorts := generic_levels[i].split(', ').map(f.short_module(it)).join(', ') res += '<$genshorts' } res += '>' diff --git a/vlib/v/fmt/tests/generic_structs_keep.vv b/vlib/v/fmt/tests/generic_structs_keep.vv index c021c7c763..ecbdaf042d 100644 --- a/vlib/v/fmt/tests/generic_structs_keep.vv +++ b/vlib/v/fmt/tests/generic_structs_keep.vv @@ -36,7 +36,7 @@ fn main() { println(x.model) println(x.permission) // - mut a := Repo{ + mut a := Repo{ model: User{ name: 'joe' } diff --git a/vlib/v/fmt/tests/generic_structs_using_mod_keep.vv b/vlib/v/fmt/tests/generic_structs_using_mod_keep.vv new file mode 100644 index 0000000000..dbe2a2f9bf --- /dev/null +++ b/vlib/v/fmt/tests/generic_structs_using_mod_keep.vv @@ -0,0 +1,8 @@ +import v.fmt.tests.obj + +struct GenericStruct { +} + +fn main() { + _ := GenericStruct{} +} diff --git a/vlib/v/fmt/tests/obj/obj.v b/vlib/v/fmt/tests/obj/obj.v new file mode 100644 index 0000000000..00900f4162 --- /dev/null +++ b/vlib/v/fmt/tests/obj/obj.v @@ -0,0 +1,3 @@ +module obj + +pub struct Test {} diff --git a/vlib/v/tests/generics_test.v b/vlib/v/tests/generics_test.v index 97a5a64253..f738de3e92 100644 --- a/vlib/v/tests/generics_test.v +++ b/vlib/v/tests/generics_test.v @@ -306,13 +306,13 @@ pub mut: // return Repo{db: db} // } fn test_generic_struct() { - mut a := Repo{ + mut a := Repo{ model: User{ name: 'joe' } } assert a.model.name == 'joe' - mut b := Repo{ + mut b := Repo{ permission: Permission{ name: 'superuser' } @@ -573,8 +573,8 @@ fn test_generic_detection() { }) // this final case challenges your scanner :-) - assert boring_function>, map[string][]int>>(TandU>, map[string][]int>{ - t: TandU>{ + assert boring_function>, map[string][]int>>(TandU>, map[string][]int>{ + t: TandU>{ t: 20 u: MultiLevel{ foo: Empty_{} diff --git a/vlib/v/tests/str_gen_test.v b/vlib/v/tests/str_gen_test.v index 4641071f8c..0641751930 100644 --- a/vlib/v/tests/str_gen_test.v +++ b/vlib/v/tests/str_gen_test.v @@ -321,7 +321,7 @@ struct MultiGenericStruct { } fn test_multi_generic_struct() { - x := MultiGenericStruct{} + x := MultiGenericStruct{} assert '$x' == 'MultiGenericStruct{\n t: TestStruct{\n x: 0\n }\n x: TestStruct{\n x: 0\n }\n}' assert x.str() == 'MultiGenericStruct{\n t: TestStruct{\n x: 0\n }\n x: TestStruct{\n x: 0\n }\n}' }