From 86d2063b28803dfb73954107f64a6ed0d104c064 Mon Sep 17 00:00:00 2001 From: kbkpbot Date: Wed, 5 Nov 2025 16:10:03 +0800 Subject: [PATCH] parser: fix vfmt comment in struct init after the update expr (fix #24361) (#25668) --- ...ruct_init_with_update_expr_comment_keep.vv | 20 +++++++++++++++++++ vlib/v/parser/struct.v | 2 +- 2 files changed, 21 insertions(+), 1 deletion(-) create mode 100644 vlib/v/fmt/tests/struct_init_with_update_expr_comment_keep.vv diff --git a/vlib/v/fmt/tests/struct_init_with_update_expr_comment_keep.vv b/vlib/v/fmt/tests/struct_init_with_update_expr_comment_keep.vv new file mode 100644 index 000000000..d052332bd --- /dev/null +++ b/vlib/v/fmt/tests/struct_init_with_update_expr_comment_keep.vv @@ -0,0 +1,20 @@ +module main + +struct MyStruct { + a int + b int +} + +fn x() { + k := MyStruct{} + _ := MyStruct{ + ...k // same line comment + // keep comment here + } + + _ := MyStruct{ + ...k // same line comment + // keep comment here + b: 100 + } +} diff --git a/vlib/v/parser/struct.v b/vlib/v/parser/struct.v index d9b4ead08..29e856f60 100644 --- a/vlib/v/parser/struct.v +++ b/vlib/v/parser/struct.v @@ -582,7 +582,7 @@ fn (mut p Parser) struct_init(typ_str string, kind ast.StructInitKind, is_option update_expr_pos = p.tok.pos() p.check(.ellipsis) update_expr = p.expr(0) - update_expr_comments << p.eat_comments(same_line: true) + update_expr_comments << p.eat_comments() has_update_expr = true } else { prev_comments = p.eat_comments() -- 2.39.5