From 8197463b08023c046baef42646c861b17de17d65 Mon Sep 17 00:00:00 2001 From: Delyan Angelov Date: Wed, 11 Nov 2020 21:40:56 +0200 Subject: [PATCH] vfmt: fix `x := Repo{}` --- vlib/v/fmt/fmt.v | 9 +++++++++ vlib/v/fmt/tests/generic_structs_keep.vv | 17 +++++++++++++++++ 2 files changed, 26 insertions(+) diff --git a/vlib/v/fmt/fmt.v b/vlib/v/fmt/fmt.v index d03d88e5bb..472bd90ea6 100644 --- a/vlib/v/fmt/fmt.v +++ b/vlib/v/fmt/fmt.v @@ -1272,6 +1272,15 @@ pub fn (mut f Fmt) short_module(name string) string { if !name.contains('.') { return name } + if name.ends_with('>') { + x := name.trim_suffix('>').split('<') + if x.len == 2 { + main := f.short_module(x[0]) + genlist := x[1].split(',').map(f.short_module(it)).join(',') + res := '$main<${genlist}>' + return res + } + } vals := name.split('.') if vals.len < 2 { return name diff --git a/vlib/v/fmt/tests/generic_structs_keep.vv b/vlib/v/fmt/tests/generic_structs_keep.vv index acb5a1a591..cdee4c629a 100644 --- a/vlib/v/fmt/tests/generic_structs_keep.vv +++ b/vlib/v/fmt/tests/generic_structs_keep.vv @@ -16,6 +16,16 @@ pub mut: permission U } +struct User { +mut: + name string +} + +struct Permission { +pub mut: + name string +} + fn main() { foo_int := Foo{2} assert foo_int.value() == '2' @@ -25,4 +35,11 @@ fn main() { println(x.db) println(x.model) println(x.permission) + // + mut a := Repo{ + model: User{ + name: 'joe' + } + } + println(a.model.name) }