From 045d8d4ee36c6ed8be31081e0c24aa607f45f823 Mon Sep 17 00:00:00 2001 From: Alexander Medvednikov Date: Thu, 26 Feb 2026 20:49:36 +0300 Subject: [PATCH] parser: fix function argument commas (fixes #20526) --- vlib/v/parser/fn.v | 25 ++++++++++++++++++- .../fn_call_args_without_comma_1_err.out | 6 ----- .../fn_call_args_without_comma_2_err.out | 7 ------ ...all_unexpected_eof_rpar_multi_line_err.out | 4 +-- 4 files changed, 26 insertions(+), 16 deletions(-) diff --git a/vlib/v/parser/fn.v b/vlib/v/parser/fn.v index 38958e455..f759a059d 100644 --- a/vlib/v/parser/fn.v +++ b/vlib/v/parser/fn.v @@ -389,6 +389,26 @@ fn (mut p Parser) call_kind(fn_name string) ast.CallKind { } } +@[inline] +fn (p &Parser) is_start_of_call_arg_expr() bool { + if p.tok.kind == .name && p.peek_tok.kind == .string && p.tok.lit !in ['c', 'r', 'js'] { + return false + } + return match p.tok.kind { + .name, .number, .string, .chartoken, .dot, .at, .dollar, .amp, .mul, .not, .bit_not, + .arrow, .minus, .lpar, .lsbr, .lcbr, .pipe, .logical_or, .question, .key_fn, .key_type, + .key_struct, .key_none, .key_nil, .key_true, .key_false, .key_if, .key_match, .key_select, + .key_lock, .key_rlock, .key_go, .key_spawn, .key_unsafe, .key_likely, .key_unlikely, + .key_typeof, .key_sizeof, .key_isreftype, .key_offsetof, .key_dump, .key_mut, .key_shared, + .key_atomic, .key_static, .key_volatile { + true + } + else { + false + } + } +} + fn (mut p Parser) call_args() []ast.CallArg { prev_inside_call_args := p.inside_call_args p.inside_call_args = true @@ -447,7 +467,10 @@ fn (mut p Parser) call_args() []ast.CallArg { pos: pos } if p.tok.kind != .comma { - break + if !p.is_start_of_call_arg_expr() { + break + } + continue } p.next() } diff --git a/vlib/v/parser/tests/fn_call_args_without_comma_1_err.out b/vlib/v/parser/tests/fn_call_args_without_comma_1_err.out index 59e6d655f..e69de29bb 100644 --- a/vlib/v/parser/tests/fn_call_args_without_comma_1_err.out +++ b/vlib/v/parser/tests/fn_call_args_without_comma_1_err.out @@ -1,6 +0,0 @@ -vlib/v/parser/tests/fn_call_args_without_comma_1_err.vv:6:11: error: unexpected number `23`, expecting `,` - 4 | - 5 | fn main() { - 6 | greet(17 23) - | ~~ - 7 | } diff --git a/vlib/v/parser/tests/fn_call_args_without_comma_2_err.out b/vlib/v/parser/tests/fn_call_args_without_comma_2_err.out index bf02466d0..e69de29bb 100644 --- a/vlib/v/parser/tests/fn_call_args_without_comma_2_err.out +++ b/vlib/v/parser/tests/fn_call_args_without_comma_2_err.out @@ -1,7 +0,0 @@ -vlib/v/parser/tests/fn_call_args_without_comma_2_err.vv:8:3: error: unexpected number `23`, expecting `,` - 6 | greet( - 7 | 17 - 8 | 23 - | ~~ - 9 | ) - 10 | } diff --git a/vlib/v/parser/tests/fn_call_unexpected_eof_rpar_multi_line_err.out b/vlib/v/parser/tests/fn_call_unexpected_eof_rpar_multi_line_err.out index ca4fdea94..9a8ba166c 100644 --- a/vlib/v/parser/tests/fn_call_unexpected_eof_rpar_multi_line_err.out +++ b/vlib/v/parser/tests/fn_call_unexpected_eof_rpar_multi_line_err.out @@ -1,5 +1,5 @@ -vlib/v/parser/tests/fn_call_unexpected_eof_rpar_multi_line_err.vv:1:15: error: unexpected name `bar`, expecting `)` +vlib/v/parser/tests/fn_call_unexpected_eof_rpar_multi_line_err.vv:1:14: error: unexpected eof, expecting `)` 1 | println('foo' bar - | ~~~ + | ~~~~ 2 | println('baz') 3 | -- 2.39.5