From 2e8b9e3b92a508bb6755ed5e2519a92efd66db85 Mon Sep 17 00:00:00 2001 From: Makhnev Petr <51853996+i582@users.noreply.github.com> Date: Fri, 21 Oct 2022 11:38:19 +0400 Subject: [PATCH] v fmt: fix extra space for anon struct (#16131) --- doc/docs.md | 2 +- examples/gg/arcs_and_slices.v | 2 +- vlib/v/checker/tests/anon_structs_visibility/amod/amod.v | 2 +- vlib/v/fmt/struct.v | 7 ++++--- vlib/v/tests/struct_test.v | 2 +- 5 files changed, 8 insertions(+), 7 deletions(-) diff --git a/doc/docs.md b/doc/docs.md index c7121bae41..67ab598c9d 100644 --- a/doc/docs.md +++ b/doc/docs.md @@ -2133,7 +2133,7 @@ with a struct name. ```v struct Book { - author struct { + author struct { name string age int } diff --git a/examples/gg/arcs_and_slices.v b/examples/gg/arcs_and_slices.v index ac0695ddc7..f65fec6f6e 100644 --- a/examples/gg/arcs_and_slices.v +++ b/examples/gg/arcs_and_slices.v @@ -19,7 +19,7 @@ enum Selection { struct App { mut: gg &gg.Context = unsafe { nil } - mouse struct { + mouse struct { mut: x f32 y f32 diff --git a/vlib/v/checker/tests/anon_structs_visibility/amod/amod.v b/vlib/v/checker/tests/anon_structs_visibility/amod/amod.v index e2b4901573..f978053bf8 100644 --- a/vlib/v/checker/tests/anon_structs_visibility/amod/amod.v +++ b/vlib/v/checker/tests/anon_structs_visibility/amod/amod.v @@ -2,7 +2,7 @@ module amod pub struct Foo { pub mut: - bar struct { + bar struct { pub mut: baz int } diff --git a/vlib/v/fmt/struct.v b/vlib/v/fmt/struct.v index 898a87be6e..14fd48ea28 100644 --- a/vlib/v/fmt/struct.v +++ b/vlib/v/fmt/struct.v @@ -12,13 +12,14 @@ pub fn (mut f Fmt) struct_decl(node ast.StructDecl, is_anon bool) { f.write('pub ') } if node.is_union { - f.write('union ') + f.write('union') } else { - f.write('struct ') + f.write('struct') } - f.write_language_prefix(node.language) name := node.name.after('.') // strip prepended module if !is_anon { + f.write(' ') + f.write_language_prefix(node.language) f.write(name) } f.write_generic_types(node.generic_types) diff --git a/vlib/v/tests/struct_test.v b/vlib/v/tests/struct_test.v index 18f675d617..d2c7f1ae1e 100644 --- a/vlib/v/tests/struct_test.v +++ b/vlib/v/tests/struct_test.v @@ -416,7 +416,7 @@ fn test_struct_update() { // Test anon structs struct Book { x Foo - author struct { + author struct { name string age int }