From cb4d16ff3a7140385a0c30c88763921b3cd605b5 Mon Sep 17 00:00:00 2001 From: Felipe Pena Date: Mon, 17 Mar 2025 11:32:29 -0300 Subject: [PATCH] fmt: fix comment handling on ending of struct decl (fix #23947) (#23948) --- vlib/v/ast/ast.v | 2 +- vlib/v/fmt/tests/struct_end_comments_keep.vv | 11 +++++++++++ vlib/v/parser/struct.v | 5 +++++ 3 files changed, 17 insertions(+), 1 deletion(-) create mode 100644 vlib/v/fmt/tests/struct_end_comments_keep.vv diff --git a/vlib/v/ast/ast.v b/vlib/v/ast/ast.v index 5c793e0ee..74060dd20 100644 --- a/vlib/v/ast/ast.v +++ b/vlib/v/ast/ast.v @@ -351,7 +351,6 @@ pub: option_pos token.Pos pre_comments []Comment comments []Comment - next_comments []Comment i int has_default_expr bool has_prev_newline bool @@ -365,6 +364,7 @@ pub: is_deprecated bool is_embed bool pub mut: + next_comments []Comment is_recursive bool is_part_of_union bool container_typ Type diff --git a/vlib/v/fmt/tests/struct_end_comments_keep.vv b/vlib/v/fmt/tests/struct_end_comments_keep.vv new file mode 100644 index 000000000..6fef53e4b --- /dev/null +++ b/vlib/v/fmt/tests/struct_end_comments_keep.vv @@ -0,0 +1,11 @@ +module main + +pub struct CSDL_GamepadBinding { +pub mut: + output_type u8 + // TODO: BELONGS ABOVE // union { + // SDL_GamepadButton button; struct { + // SDL_GamepadAxis axis; int axis_min; int axis_max; } axis; } output +} + +pub type GamepadBinding = CSDL_GamepadBinding diff --git a/vlib/v/parser/struct.v b/vlib/v/parser/struct.v index 54ac81c05..b2677b0ad 100644 --- a/vlib/v/parser/struct.v +++ b/vlib/v/parser/struct.v @@ -212,6 +212,11 @@ fn (mut p Parser) struct_decl(is_anon bool) ast.StructDecl { mut field_pos := token.Pos{} mut option_pos := token.Pos{} + if p.tok.kind == .rcbr { + ast_fields.last().next_comments << pre_field_comments + break + } + if is_embed { // struct embedding type_pos = p.tok.pos() -- 2.39.5