From 8d518206205a081c1fe6edadc55060343a8be29d Mon Sep 17 00:00:00 2001 From: Felipe Pena Date: Wed, 29 Jan 2025 08:36:45 -0300 Subject: [PATCH] parser: fix anon fn return type option/result followed by comment parsing in vfmt mode (fix #23607) (#23608) --- .../anon_fn_result_return_with_comment_keep.vv | 14 ++++++++++++++ vlib/v/parser/parse_type.v | 2 +- 2 files changed, 15 insertions(+), 1 deletion(-) create mode 100644 vlib/v/fmt/tests/anon_fn_result_return_with_comment_keep.vv diff --git a/vlib/v/fmt/tests/anon_fn_result_return_with_comment_keep.vv b/vlib/v/fmt/tests/anon_fn_result_return_with_comment_keep.vv new file mode 100644 index 000000000..8dceffd78 --- /dev/null +++ b/vlib/v/fmt/tests/anon_fn_result_return_with_comment_keep.vv @@ -0,0 +1,14 @@ +module main + +pub interface Command { + name string // Command name as used on CLI + desc string // Single line description + help string // Detailed and formated description + arg_min int // Minimal argument number expected + arg_max int // Maximal argument number expected + exec fn (s []string) ! // Command callback. +} + +fn main() { + println('Hello') +} diff --git a/vlib/v/parser/parse_type.v b/vlib/v/parser/parse_type.v index 83b42b621..6ff794921 100644 --- a/vlib/v/parser/parse_type.v +++ b/vlib/v/parser/parse_type.v @@ -479,7 +479,7 @@ fn (mut p Parser) parse_type() ast.Type { is_attr := p.tok.kind == .at if p.tok.line_nr > line_nr || p.tok.kind in [.comma, .rpar, .assign] - || (is_attr || is_required_field) { + || (is_attr || is_required_field) || p.tok.kind == .comment { mut typ := ast.void_type if is_option { typ = typ.set_flag(.option) -- 2.39.5