diff --git a/vlib/v/fmt/fmt.v b/vlib/v/fmt/fmt.v index 411e20bba9..ed84aef41f 100644 --- a/vlib/v/fmt/fmt.v +++ b/vlib/v/fmt/fmt.v @@ -1584,14 +1584,6 @@ pub fn (mut f Fmt) at_expr(node ast.AtExpr) { } pub fn (mut f Fmt) call_expr(node ast.CallExpr) { - old_short_arg_state := f.use_short_fn_args - f.use_short_fn_args = false - if node.args.len > 0 && node.args.last().expr is ast.StructInit { - struct_expr := node.args.last().expr as ast.StructInit - if struct_expr.typ == ast.void_type { - f.use_short_fn_args = true - } - } for arg in node.args { f.comments(arg.comments, {}) } @@ -1639,7 +1631,6 @@ pub fn (mut f Fmt) call_expr(node ast.CallExpr) { f.write(')') f.or_expr(node.or_block) f.comments(node.comments, has_nl: false) - f.use_short_fn_args = old_short_arg_state } fn (mut f Fmt) write_generic_if_require(node ast.CallExpr) { @@ -1662,10 +1653,19 @@ fn (mut f Fmt) write_generic_if_require(node ast.CallExpr) { pub fn (mut f Fmt) call_args(args []ast.CallArg) { f.single_line_fields = true + old_short_arg_state := f.use_short_fn_args + f.use_short_fn_args = false defer { f.single_line_fields = false + f.use_short_fn_args = old_short_arg_state } for i, arg in args { + if i == args.len - 1 && arg.expr is ast.StructInit { + struct_expr := arg.expr as ast.StructInit + if struct_expr.typ == ast.void_type { + f.use_short_fn_args = true + } + } if arg.is_mut { f.write(arg.share.str() + ' ') } diff --git a/vlib/v/fmt/tests/fn_trailing_arg_syntax_expected.vv b/vlib/v/fmt/tests/fn_trailing_arg_syntax_expected.vv index 1f1cd4a7ce..83761672b3 100644 --- a/vlib/v/fmt/tests/fn_trailing_arg_syntax_expected.vv +++ b/vlib/v/fmt/tests/fn_trailing_arg_syntax_expected.vv @@ -22,6 +22,10 @@ fn main() { y: 0 } ) + bar2_func({}, {}) + bar2_func({ x: 's' }, + x: 's' + ) baz_func('foo', 'bar', x: 0 y: 0 @@ -40,4 +44,7 @@ fn main() { fn bar_func(bar Bar) { } +fn bar2_func(bar1 Bar, bar2 Bar) { +} + fn baz_func(a string, b string, baz Baz) {} diff --git a/vlib/v/fmt/tests/fn_trailing_arg_syntax_input.vv b/vlib/v/fmt/tests/fn_trailing_arg_syntax_input.vv index 5ea1f6465e..f1d48fe1e9 100644 --- a/vlib/v/fmt/tests/fn_trailing_arg_syntax_input.vv +++ b/vlib/v/fmt/tests/fn_trailing_arg_syntax_input.vv @@ -16,6 +16,8 @@ fn main() { x: 0 y: 0 }) + bar2_func({}, {}) + bar2_func({x: 's'}, {x: 's'}) baz_func('foo', 'bar', x: 0 y: 0 ) @@ -28,4 +30,7 @@ fn main() { fn bar_func(bar Bar) { } +fn bar2_func(bar1 Bar, bar2 Bar) { +} + fn baz_func(a string, b string, baz Baz) {}