From 7472a745e0cf80efce457cb5c4494003190e26b3 Mon Sep 17 00:00:00 2001 From: Felipe Pena Date: Wed, 23 Jul 2025 14:48:03 -0300 Subject: [PATCH] parser: allow keyword as struct param key on fn call (fix #24957) (#24958) --- vlib/v/parser/fn.v | 2 +- .../fns/call_struct_params_with_keyword_test.v | 13 +++++++++++++ 2 files changed, 14 insertions(+), 1 deletion(-) create mode 100644 vlib/v/tests/fns/call_struct_params_with_keyword_test.v diff --git a/vlib/v/parser/fn.v b/vlib/v/parser/fn.v index 19237289d8..3ce9356817 100644 --- a/vlib/v/parser/fn.v +++ b/vlib/v/parser/fn.v @@ -141,7 +141,7 @@ fn (mut p Parser) call_args() []ast.CallArg { array_decompose = true } mut expr := ast.empty_expr - if p.tok.kind in [.name, .key_type] && p.peek_tok.kind == .colon { + if p.peek_tok.kind == .colon { // `foo(key:val, key2:val2)` expr = p.struct_init('void_type', .short_syntax, false) } else { diff --git a/vlib/v/tests/fns/call_struct_params_with_keyword_test.v b/vlib/v/tests/fns/call_struct_params_with_keyword_test.v new file mode 100644 index 0000000000..8236a6b12b --- /dev/null +++ b/vlib/v/tests/fns/call_struct_params_with_keyword_test.v @@ -0,0 +1,13 @@ +@[params] +struct Config { + dump bool +} + +fn test_main() { + opt := Config{} + run('x', dump: opt.dump)! +} + +fn run(source string, config Config) ! { + dump(config) +}